Int32 FileID = 102;
string strConnection = WebConfigurationManager.ConnectionStrings["IntranetaddonConnectionString"].ConnectionString;
string strSQL = "Select * from wp_DeviationReportFiles where FileID =" + FileID + "";
SqlConnection myConnection = new SqlConnection(strConnection);
myConnection.Open();
SqlCommand cmdGetFile = new SqlCommand(strSQL, myConnection);
SqlDataReader myDataReader;
myDataReader = cmdGetFile.ExecuteReader();
if (myDataReader.Read())
{
Int32 myyInt = Convert.ToInt32(myDataReader["fileSize"]);
byte[] result = (byte[])myDataReader["BinaryData"];
Response.ContentType = "text/plain";
Response.OutputStream.Write(result, 0, myyInt);
Response.AddHeader("Content-Disposition", "attachment;filename=" + myDataReader["FileName"].ToString());
}
else
{
Response.Write("File Not Found.");
}
You need to create an account or log in to post comments to this site.