简体   繁体   中英

Open a Byte[] as Image/PDF in a new Tab or window

I have access a file(say image or pdf) from another server through impersonation in asp.net C#.

The problem is, this impersonation is in another library and file is returned as byte array.

Now I want to open this byte array of image/pdf in a new tab or window.

Example: Suppose I have chosen to view "file1.tiff", the request will go to the respective server with proper credential to search for that file. if file is found(main motive) it will convert this "file1.tiff" to byte array(say buffer) and will return this file. This is received by " byte[] image ". Now I want to open this very image in a new tab or window to view without asking a dialog box for "Open Save Or Cancel".

byte[] image= impFile.ViewFile(fileName);

I have already tried :

Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "image/tiff";    
Response.AddHeader("content-length", image.Length.ToString());
Response.BinaryWrite(image);
Response.Flush();Response.End();

But it has two problems :-

  1. It is asking for "Open Save or cancel".

  2. Doesn't open in a new window but open with default application assigned for that extension.

You can use HttpResponse.WriteFile method to send the stream to client directly. Writes the specified file directly to an HTTP response output stream.

You can create the IHttpHandler to send the stream, thus avoid some page life circle, increase the performance. Here is the Link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM