The following piece of code can be used to write a memory stream to any browser. In my case its a pdf file so i am using “HttpContext.Current.Response.ContentType = “application/pdf” ” only this line is changed when there is amy other type of file in memory stream:
Public Sub ViewMS(ByVal fs As MemoryStream) Dim buffer(fs.Length) As Byte fs.Position = 0 fs.Read(buffer, 0, fs.Length) HttpContext.Current.Response.Buffer = False HttpContext.Current.Response.ContentType = "application/pdf" 'In my case its a pdf HttpContext.Current.Response.OutputStream.Write(fs.GetBuffer(), 0, fs.Length) HttpContext.Current.Response.Flush() HttpContext.Current.Response.End() fs.Dispose() fs.Close() End Sub
Hope this may help anyone



How do you do this in C#? fs.Length is long, and C# requires that field to be int.
Thanks!
Larry,
you can use
int length = Convert.ToInt32(fs.Length);
and then use “length” instead of “fs.length” in the above code.
Hi ,
I’ve got the error :
“File does not begin with ‘%PDF-”
This is a problem with the data or with the code ?
The problem of ‘%PDF-’ is due to the version of the adobe reader you have on your system, try to get the latest version of adobe reader and then try again. Hope this may help.
P.S. Also sometimes the adobe plugin for the browser (to render pdf in it) becomes corrupt so reinstalling it might help.
I forgot , “thanks”