try { conn.Open(); SqlDataReader dr=cmd.ExecuteReader(); while (dr.Read()) { buffByte = ((byte[])dr[0]); } conn.Close(); } catch(System.Exception ee) { MessageBox.Show(ee.Message ); } System.IO.MemoryStream ms = new System.IO.MemoryStream(buffByte); // set the file name from the open file dialog string fileName = @"f:\ee.doc"; System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); fs.Write(buffByte, 0, buffByte.Length); fs.Close();
还有方法是真接上传文件到指定目录,数据库存储路径。
谢谢
下面是我的代码:
string strconn="..."; //建立Command命令
byte[] buffByte = null; SqlConnection conn=new SqlConnection(strconn);
SqlCommand cmd=new SqlCommand();
cmd.CommandText="wordtableselect";
cmd.CommandType=CommandType.StoredProcedure;
cmd.Connection=conn; //创建Parameter
cmd.Parameters.Add("@id",System.Data.SqlDbType.Int);
cmd.Parameters[0].Value = 1;
try
{
conn.Open();
SqlDataReader dr=cmd.ExecuteReader();
while (dr.Read())
{
buffByte = ((byte[])dr[0]);
}
conn.Close();
}
catch(System.Exception ee)
{
MessageBox.Show(ee.Message );
}
System.IO.MemoryStream ms = new System.IO.MemoryStream(buffByte);
// set the file name from the open file dialog
string fileName = @"f:\ee.doc";
System.IO.FileStream fs =
new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); fs.Write(buffByte, 0, buffByte.Length); fs.Close();