where t.id == 9
select new
{
t.wordData // image类型 word文档
};
var dss = ds.First();
string filename = @"c:\a.docx";
FileStream fs;
try
{
byte[] bytes = new byte[0];
fs = new FileStream(filename, FileMode.Create);
bytes = dss.wordData.ToArray();
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
catch (IOException ex)
{
richTextBox1.Text = ex.Message;
}
这段代码虽然在c盘新建a.docx文件,但打开无效,请问大家是怎么回事?
谢谢!!!
6 个解决方案
#1
bytes = dss.wordData.ToArray();
改为:
试试
改为:
bytes=System.Text.Encoding.UTF8.GetBytes(dss.wordData);
试试
#2
提示错误!cannot convert from System.data.linq.binary to char[]
#3
确认传上去的是docx文件
private void button1_Click(object sender, EventArgs e)
{
byte[] buffer = File.ReadAllBytes(@"C:\Users\Administrator\Desktop\生成加密报告.doc");
using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=northwind"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("Insert Into Employees(Photo) SELECT @buffer"))
{
cmd.Parameters.AddWithValue("@buffer", buffer);
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
NorthwindDataContext dataContext = new NorthwindDataContext();
var query = from emp in dataContext.GetTable<Employees>()
where emp.EmployeeID.Equals(10)
select emp;
Employees employee = query.First();
byte[] buffer = employee.Photo.ToArray();
string fileName = "D:\\123.doc";
FileStream fs = File.Create(fileName);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
}
是可以打开的
private void button1_Click(object sender, EventArgs e)
{
byte[] buffer = File.ReadAllBytes(@"C:\Users\Administrator\Desktop\生成加密报告.doc");
using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=northwind"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("Insert Into Employees(Photo) SELECT @buffer"))
{
cmd.Parameters.AddWithValue("@buffer", buffer);
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
NorthwindDataContext dataContext = new NorthwindDataContext();
var query = from emp in dataContext.GetTable<Employees>()
where emp.EmployeeID.Equals(10)
select emp;
Employees employee = query.First();
byte[] buffer = employee.Photo.ToArray();
string fileName = "D:\\123.doc";
FileStream fs = File.Create(fileName);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
}
是可以打开的
#4
去这里看下载吧
http://topic.csdn.net/u/20120419/16/6d31708e-e8f9-4799-80bf-78f17b039161.html?80014
链接过去大量的函数 其中就有你说的这个功能
http://topic.csdn.net/u/20120419/16/6d31708e-e8f9-4799-80bf-78f17b039161.html?80014
链接过去大量的函数 其中就有你说的这个功能
#5
算了把 我给你找到地址了
共享链接:http://163.fm/B38gF2z 提取码:l2rFuavN
以后可能会换 就去楼上看那个帖子吧
共享链接:http://163.fm/B38gF2z 提取码:l2rFuavN
以后可能会换 就去楼上看那个帖子吧
#6
如果上传的文件没有问题的话,下载下来只是把二进制流转换成指定类型文件而已。
private byte[] wordflow;
//从数据库中获取并为workflow赋值;
void SaveWordFile()
{
SaveFileDialog saveFile=new SaveFileDialog();
saveFile.FileName="文件名";
saveFile.Filter="word文件(*.doc,*.docx)|*.doc;*.docx";
if(saveFile.ShowDialog()==DialogResult.OK)
{
string filePath=saveFile.FileName;
File.WriteAllBytes(filePath,workflow);
MessageBox.Show("导出Word成功!");
}
}
private byte[] wordflow;
//从数据库中获取并为workflow赋值;
void SaveWordFile()
{
SaveFileDialog saveFile=new SaveFileDialog();
saveFile.FileName="文件名";
saveFile.Filter="word文件(*.doc,*.docx)|*.doc;*.docx";
if(saveFile.ShowDialog()==DialogResult.OK)
{
string filePath=saveFile.FileName;
File.WriteAllBytes(filePath,workflow);
MessageBox.Show("导出Word成功!");
}
}
#1
bytes = dss.wordData.ToArray();
改为:
试试
改为:
bytes=System.Text.Encoding.UTF8.GetBytes(dss.wordData);
试试
#2
提示错误!cannot convert from System.data.linq.binary to char[]
#3
确认传上去的是docx文件
private void button1_Click(object sender, EventArgs e)
{
byte[] buffer = File.ReadAllBytes(@"C:\Users\Administrator\Desktop\生成加密报告.doc");
using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=northwind"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("Insert Into Employees(Photo) SELECT @buffer"))
{
cmd.Parameters.AddWithValue("@buffer", buffer);
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
NorthwindDataContext dataContext = new NorthwindDataContext();
var query = from emp in dataContext.GetTable<Employees>()
where emp.EmployeeID.Equals(10)
select emp;
Employees employee = query.First();
byte[] buffer = employee.Photo.ToArray();
string fileName = "D:\\123.doc";
FileStream fs = File.Create(fileName);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
}
是可以打开的
private void button1_Click(object sender, EventArgs e)
{
byte[] buffer = File.ReadAllBytes(@"C:\Users\Administrator\Desktop\生成加密报告.doc");
using (SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=northwind"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("Insert Into Employees(Photo) SELECT @buffer"))
{
cmd.Parameters.AddWithValue("@buffer", buffer);
cmd.Connection = conn;
cmd.ExecuteNonQuery();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
NorthwindDataContext dataContext = new NorthwindDataContext();
var query = from emp in dataContext.GetTable<Employees>()
where emp.EmployeeID.Equals(10)
select emp;
Employees employee = query.First();
byte[] buffer = employee.Photo.ToArray();
string fileName = "D:\\123.doc";
FileStream fs = File.Create(fileName);
fs.Write(buffer, 0, buffer.Length);
fs.Flush();
fs.Close();
}
}
是可以打开的
#4
去这里看下载吧
http://topic.csdn.net/u/20120419/16/6d31708e-e8f9-4799-80bf-78f17b039161.html?80014
链接过去大量的函数 其中就有你说的这个功能
http://topic.csdn.net/u/20120419/16/6d31708e-e8f9-4799-80bf-78f17b039161.html?80014
链接过去大量的函数 其中就有你说的这个功能
#5
算了把 我给你找到地址了
共享链接:http://163.fm/B38gF2z 提取码:l2rFuavN
以后可能会换 就去楼上看那个帖子吧
共享链接:http://163.fm/B38gF2z 提取码:l2rFuavN
以后可能会换 就去楼上看那个帖子吧
#6
如果上传的文件没有问题的话,下载下来只是把二进制流转换成指定类型文件而已。
private byte[] wordflow;
//从数据库中获取并为workflow赋值;
void SaveWordFile()
{
SaveFileDialog saveFile=new SaveFileDialog();
saveFile.FileName="文件名";
saveFile.Filter="word文件(*.doc,*.docx)|*.doc;*.docx";
if(saveFile.ShowDialog()==DialogResult.OK)
{
string filePath=saveFile.FileName;
File.WriteAllBytes(filePath,workflow);
MessageBox.Show("导出Word成功!");
}
}
private byte[] wordflow;
//从数据库中获取并为workflow赋值;
void SaveWordFile()
{
SaveFileDialog saveFile=new SaveFileDialog();
saveFile.FileName="文件名";
saveFile.Filter="word文件(*.doc,*.docx)|*.doc;*.docx";
if(saveFile.ShowDialog()==DialogResult.OK)
{
string filePath=saveFile.FileName;
File.WriteAllBytes(filePath,workflow);
MessageBox.Show("导出Word成功!");
}
}