How do I back up .doc documents in a SQL Server database?


I am saving a .doc file to a SQL Server database as varbinary(max) using the C# code below.

I am able to save the file, but when I retrieve the file back and want to display the contents on the web page, my code is downloading the file and I am in great confusion about how to handle it.

The exact functionality I am looking for is the way uploads the resume and gives a preview of it. My code is :

byte[] fileContent = new byte[fuResume.PostedFile.ContentLength];
fuResume.PostedFile.InputStream.Read(fileContent, 0, fuResume.PostedFile.ContentLength);
//lblAppliedMessage.Text = ByteArrayToString(fileContent);

//lblAppliedMessage.Text = BitConverter.ToString(fileContent).Replace("-", string.Empty);
byte[] btYourDoc;
btYourDoc = fileContent;

Response.ContentType = "application/ms-word";
Response.AddHeader("Content-Disposition", "inline;filename=yourfilename.doc");
Response.OutputStream.Write(btYourDoc, 0, fileContent.Length);



squillman is right. There are tons of third party components that do Word -> HTML conversion.

One other option, which may be more appropriate for an intranet site, is to install Word on the server.

An example of this is here:

Effectively, the doc is opened, saved out as HTML, then subsequent requests can retrieve the HTML version of the file for preview.

Office automation server side has many pitfalls, however - see for more information.