110,534
社区成员
发帖
与我相关
我的任务
分享
//下载方法
public void downloadfile(String filename)
{
SqlDataReader dr = null;
SqlConnection objCn = new SqlConnection("Data Source=10.66.4.188;Initial Catalog=File;Persist Security Info=True;Connect Timeout=600;User ID=shangguanguanjun;Password=111111");
SqlCommand cm = new SqlCommand("select main from Fileupdate where Fname='"+filename+"'");
cm.Connection = objCn;
objCn.Open();
try
{
dr = cm.ExecuteReader(); //如何知道读取的进度?做进度条用。。
byte[] File001 = null;
if (dr.Read())
{
File001 = (byte[])dr[0];
}
objCn.Close();
FileStream fs = new FileStream(filename, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(File001, 0, File001.Length);
bw.Close();
fs.Close();
MessageBox.Show("下载成功!");
}
catch (Exception ex2)
{
MessageBox.Show(ex2.Message);
}
}