62,046
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
DownloadImage(Request["FileID"]);
}
private void DownloadImage(string FileID)
{
if (FileID == null || FileID == "") return;
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection())
{
conn.ConnectionString = "server=.;uid=sa;pwd=;database=文件库";
conn.Open();
using (System.Data.SqlClient.SqlCommand command = conn.CreateCommand())
{
command.CommandText = string.Format("select * from 文件表 where id='{0}'", FileID);
System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader();
try
{
if (reader.Read())
{
int size = reader.GetInt32(0);
byte[] buffer = new byte[size];
reader.GetBytes(1, 0, buffer, 0, size);
this.Response.BinaryWrite(buffer);
}
}
catch (Exception ex)
{
this.Response.Write(ex.Message);
}
finally
{
reader.Close();
}
}
conn.Close();
}
}