Ref:
ContentType string so that it specifies the appropriate file format. The syntax of this string is usually formatted as "type/subtype," where "type" is the general content category and "subtype" is the specific content type. For a full list of supported content types, refer to your Web browser documentation or the current HTTP specification. The following list outlines some common ContentType values:
"text/HTML"
"image/GIF"
"image/JPEG"
"text/plain"
"Application/msword" (for Microsoft Word files)
"Application/x-msexcel" (for Microsoft Excel files)
public DownloadContent(string ID)
{
SqlConnection con;
try
{
con = new SqlConnection();
con.ConnectionString = "YourConn";
con.Open();
string query = "your query to retrieve from db where ID = ID"
SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
string path =Convert.ToString(dr[1]);
byte[] content = System.IO.File.ReadAllBytes(path);
Response.ContentType = "Application/msword"
Response.AddHeader("Content-Disposition", "attachment;filename=somename.doc");
Context.Response.BinaryWrite(content);
}
cmd = null;
dr.Close();
con.Close();
}
catch (Exception ex)
{
}
finally
{
if(con!= null)
con.Close();
}
}