example: suppose employee id is 1.and data are saved in varbinary(max) format. when i searching a record from id...how to open stored data in msword file.
Open msword file in c#
how to open a saved file in microsoft word..
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Yin45 reputationPosted Oct 5, 2012, 12:55 AM EDT
{
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter da = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
da.SelectCommand = cmd;
da.Fill(dt);
return dt;
}
catch
{
return null;
}
finally
{
con.Close();
da.Dispose();
con.Dispose();
}
}
private void download(DataTable dt)
{
Byte[] bytes = (Byte[])dt.Rows[0]["FileBinary"];
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = dt.Rows[0]["FileType"].ToString();
Response.AddHeader("content-disposition", "attachment;filename="+ dt.Rows[0]["Type_Name"].ToString() + ".DOC");
Response.BinaryWrite(bytes);
Response.Flush();
}
IN YOUR BUTTON:
string strQuery = "select * from TABLE where COLUMN=@id";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.Add("@id", SqlDbType.Int).Value = 1;
DataTable dt = GetData(cmd);
if (dt != null)
{
download(dt);
}
vikas kanani147 reputationPosted Oct 9, 2012, 1:54 AM EDT
Yin45 reputationPosted Oct 9, 2012, 1:59 AM EDT
vikas kanani147 reputationPosted Oct 9, 2012, 2:56 AM EDT
Yin45 reputationPosted Oct 9, 2012, 3:12 AM EDT