Hello
My name is Alex. I have a database in sql server :
Id int,
Name varchar(50),
ContentType varchar(50),
Data varbinary(max).
I can store MS Word .doc file into database:
protected void InsertDoc_Click(object sender, EventArgs e)
{
// Read the file and convert it to Byte Array
string filePath = "SOME FILE PATH";
string filename = Path.GetFileName(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
//insert the file into database
string strQuery = "insert into tblFiles(Name, ContentType, Data) values (@Name, @ContentType, @Data)";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename;
cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value = "application/vnd.ms-word";
cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
InsertUpdateData(cmd);
}
But I dont know how to retrive document and after open in MS Word.
Please help me ...
P.S. please type some code, if you hnow how to solve this problem.
Respect, Alex