I have change the while loop to the following and it works. And the user will open the broken file and the system will report the file is not found. Since Response.BufferOutput is set to true, Response.Flush() inside the while loop will flush the buffer and send it to the browser while the whole document is not finished writing to the response stream yet. (buffer, 0, lengthRead) ĭataLengthToRead = dataLengthToRead - lengthRead Int32 lengthRead = ms.Read(buffer, 0, blockSize) While (dataLengthToRead > 0 & Response.IsClientConnected) Response.ContentType = "application/octet-stream" Response.AddHeader("Content-Length", ()) Add the file size into the response header Response.AddHeader("Content-Disposition", "inline filename=" + doc.FileName) Response.AddHeader("Content-Disposition", "attachment filename=" + doc.FileName) which will force the open/cance/save dialog to show, to the header Int blockSize = dataLengthToRead >= 5000 ? 5000 : (int)dataLengthToRead īyte buffer = new byte Using (MemoryStream ms = new MemoryStream(doc.ByteArray)) Previously my code to send the byte array as a document to browser client is as below. I will describe my problem and solution in the next post. I can just set it to a generic binary stream (application/octet-stream). However, finally I found my problem is not due to incorrect ContentType. Hope it is helpful to others who may need the information. After some searching, I have created the following xml file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |