0
Answer

How to Open a Word Document Saved as SQL Image Type in SQL Server in Asp.Net using C#

Phani

Phani

19y
1.7k
1
Hi Team,

I face some problem in retrieving the word document from SQL Server.

FileStream fs = new FileStream(@"C:\My Downloads\BRD Issues.doc", FileMode.Open, FileAccess.Read);
BinaryReader r = new
BinaryReader(fs);
byte[] bytes = new byte
[fs.Length];
for( long
i = 0; i < fs.Length; i++)
{
bytes[] = r.ReadByte();
}
r.Close();
fs.Close();

someObject.docTemplate = bytes;

************** I saved the word document, as byte[] in SQL Server 2000.

************ I accessed that byte[] from SQL Server and trying to show in a new instance of MS-Word.

byte[] byteArrayObject = new byte[ChunkSize];

// I called a service which gets the byteArray from SQL server, which it is stored in this object. From that i assigned that byte array to byteArrayObject

byteArrayObject = someObject.docTemplate.byteTemplate1;

Response.Clear();
Response.ContentType = "application/msword";
// or PDF !
Response.AppendHeader("Content-Disposition", "attachment;filename=word.doc");
Response.BinaryWrite(byteArrayObject);
Response.Flush();
Response.End();

******************* The document is opened but shows some ascii format of text is displayed in MS-Word.. How i can achieve this..
Kindly Help me out, this is my urgent assignment. Post a mail if possible..Please...

Thanks in Advance..
Phani
[email protected]


Thanks & Regards,
Phani