C#下载问题,请各位高手帮助
CheckBox chk_Select=(CheckBox)item.FindControl("chk_Select");if(chk_Select.Checked)
{
Count++;
int ID=int.Parse(item.Cells[0].Text);
SqlConnection myConnection=null;
string strDownloadSql="select FileName,Annex,FileType from Notice where ID="+ID;
try
{
myConnection = new SqlConnection("server=(local);uid=sa;pwd=159753;database=Northwind");
myConnection.Open();
SqlCommand sqlcmd=new SqlCommand(strDownloadSql,myConnection);
SqlDataReader ddr=sqlcmd.ExecuteReader();
if(ddr.Read())
{
Response.ContentType = ddr["FileType"].ToString();
Response.AddHeader("Content-Disposition","attachment;FileName="+HttpUtility.UrlEncode(ddr["FileName"].ToString(),System.Text.Encoding.UTF8 ));
Response.BinaryWrite( (byte[]) ddr["Annex"] );
Response.End();
}
}
catch(Exception ex)
{
Response.Write(ex.Message+ex.StackTrace);
}
finally
{
myConnection.Close();
}
}