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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
YinPosted Oct 9, 2012, 7:12 AM
vikas kananiPosted Oct 9, 2012, 6:56 AM
YinPosted Oct 9, 2012, 5:59 AM
vikas kananiPosted Oct 9, 2012, 5:54 AM
YinPosted Oct 5, 2012, 4:55 AM
{
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);
}