c# - Open jpg/pdf in new window -


When I try to open a file in a new window using the code given below, then open a new window Instead of downloading the document. When I open the downloaded document, it sounds good.

But I want to open the document in a new window . Thanks for your help.

WebForm2Test.aspx

  & lt; A href = "WebForm1Test.aspx" onclick = "window.open ('WebForm1Test.aspx', '_ blank')" & gt; WebForm1Test.aspx & lt; / A & gt;  

WebForm1Test.aspx.cs

  public partial class WebForm1Test: System.Web.UI.Page {secure zero page_load (object sender, EventArgs e) { // written document system. IOM .Morestream Outstream = New System. IOM Memorystream (some bj 64_ string); HttpContext.Current.Response.Expires = 0; HttpContext.Current.Response.Buffer = True; HttpContext.Current.Response.ClearContent (); String STR_File_Name = "test" HttpContext.Current.Response.AppendHeader ("content-displacement", "attachment; file name =" + test); // Known content type if (OBJ_Document.CH_Document_Extension.ToUpper () == "JPG") {HttpContext.Current.Response.AppendHeader ("content type", "image / JPEG"); } If (oBJDC.CDDDI.expression.Tupper () == "JPEG") {HTTPPTCXTC. Current. response. Append header ("content-type", "image / jpeg"); } If (OBZ document.HCDCTCextension.towper () == "PDF") {HTTPPTCXTC. Content response. App header ("content-type", "API / PDF"); } (Filestream file = new filestream ("c: \\ file.bin", FileMode.Create, System.IO.FileAccess.Write)) {byte [] bytes = new byte [outstream.Length]; Outstream.Read (byte, 0, (int) outstream.Length); File. Write (byte, 0, bytes lang); OutStream.Close (); } HttpContext.Current.Response.TransmitFile ("c: \\ file.bin"); OutStream.Close (); HttpContext.Current.Response.End (); }}  

The reason your content-target header browser is saving the file instead of a file Making it appear in the inline you still need the content type header, but try it after removing the content-nature.

If this header is used in response to the application / octet-stream content-type, the implied suggestion is that the response to the user agent is not displayed Should do this, but enter a 'Save feedback like this ...' dialog directly.

With this time "content should be saved directly, if material-nature is sent". Most browsers behave like this in my experience.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -