Sure, we pass the byte array to the following function:
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
// Buffer response so that page is sent
// after processing is complete.
context.Response.BufferOutput = true;
string contentType = string.Empty;
string contentDisposition = string.Empty;
switch (corrItemTypeId)
{
case (int)CorrItemTypeEnum.Image:
contentType = "application/octet-stream";
contentDisposition = "inline";
break;
default:
contentType = "application/msword";
contentDisposition = "attachment";
break;
}
context.Response.AddHeader("Content-Disposition", string.Format("{0};filename={1}.{2}", contentDisposition, fileName, fileExt));
// Add the file size into the response header
context.Response.AddHeader("Content-Length", data.Length.ToString());
using (MemoryStream ms = new MemoryStream(data))
{
long dataLengthToRead = ms.Length;
int blockSize = dataLengthToRead >= 5000 ? 5000 : (int)dataLengthToRead;
byte[] buffer = new byte[dataLengthToRead];
// Write the document into the response
while (dataLengthToRead > 0 && context.Response.IsClientConnected)
{
Int32 lengthRead = ms.Read(buffer, 0, blockSize);
context.Response.OutputStream.Write(buffer, 0, lengthRead);
dataLengthToRead = dataLengthToRead - lengthRead;
// do not flush since BufferOutput = true
}
context.Response.Flush();
context.Response.Close();
}
Again this works fine for SaveFormat.Doc but then the file is not opened properly in word2007 with the docx file extension. Thanks and I will try the newest version of the dll.