How to open PDF file in a new tab or window instead of downloading it (using

how to open any file in new browser tab using with c#
open pdf in new tab instead of download - javascript open pdf in new window code behind
how to open pdf file on link button click in asp net
how to open pdf file in new tab in mvc using c#
how to open pdf file in popup window in c#
open filestreamresult in new window
how to open a pdf file in using c#

This is the code for downloading the file.

System.IO.FileStream fs = new System.IO.FileStream(Path+"\\"+fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
byte[] ar = new byte[(int)fs.Length];
fs.Read(ar, 0, (int)fs.Length);

Response.AddHeader("content-disposition", "attachment;filename=" + AccNo+".pdf");
Response.ContentType = "application/octectstream";

When this code is executed, it will ask user to open or save the file. Instead of this I need to open a new tab or window and display the file. How can I achieve this?


File won't necessary be located in the website folder. It might be located in an other folder.

Instead of loading a stream into a byte array and writing it to the response stream, you should have a look at HttpResponse.TransmitFile

Response.ContentType = "Application/pdf";

If you want the PDF to open in a new window you would have to open the downloading page in a new window, for example like this:

<a href="viewpdf.aspx" target="_blank">View PDF</a>

How to Open PDF file in a new browser tab using ASP.NET with C# , I am able to open the PDF in the same browser tab by using the below -pdf-file- in-a-new-tab-or-window-instead-of-downloading-it-using-asp. Hi, I would like to open a PDF file directly inside a another tab from the browser (by using C# and I am able to open the PDF in the same browser tab by using the below code response.Cont

Response.ContentType = contentType;
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=" + fileName);


<asp:LinkButton OnClientClick="openInNewTab();" OnClick="CodeBehindMethod".../>

In javaScript:

<script type="text/javascript">
    function openInNewTab() {
        window.document.forms[0].target = '_blank'; 
        setTimeout(function () { window.document.forms[0].target = ''; }, 0);

Take care to reset target, otherwise all other calls like Response.Redirect will open in a new tab, which might be not what you want.

c How to open PDF file in a new tab or window instead of , c How to open PDF file in a new tab or window instead of downloading it (using <asp:LinkButton OnClientClick="openInNewTab();"� Here I am using iTextSharp dll for generating PDF file. I want to open PDF file instead of downloading it. So I am using below code which is working fine for me. Now pdf file is opening in browser ,now dowloading

this may help

Response.Write("'../Inventory/pages/printableads.pdf', '_newtab');");

How do I force files to open in a new tab instead of download to my , Files you click on in Luminello should, by default, open in a new tab in your browser If your PDFs are downloading instead of opening automatically in Microsoft Windows 10 will ship with two browsers: Internet Explorer 11� In this article, I will explain how to open a PDF file in a web browser using ASP.NET. Use the following procedure. Step 1. Open Visual Studio 2012 and click "File" -> "New" -> "web site". A window is opened. In this window, click "Empty Web Site Application" under Visual C#. Give the name of your application as "Open_PDF" and then click "Ok". Step 2

You have to create either another page or generic handler with the code to generate your pdf. Then that event gets triggered and the person is redirected to that page.

How to open pdf file in new tab from c# server code, How to open pdf file into new tab in browser that is saved locally in solution with c# Instead of saving file to local folder, save it to some server location; Use Response.Write with link to file on server to open in new tab. Response.Write("< script>'<Link to PDF on Server>','_blank');</script>");. 0� The option to "open PDF as a new tab in the same window" is not available on the classic track. If you have the classic track, then you will not be able to open PDFs in a tab view. Let us know if you need any help or if you have any questions.

you can return a FileResult from your MVC action.

*********************MVC action************

    public FileResult OpenPDF(parameters)
       //code to fetch your pdf byte array
       return File(pdfBytes, "application/pdf");


Use formpost to post your data to action

    var inputTag = '<input name="paramName" type="text" value="' + payloadString + '">';
    var form = document.createElement("form");
    jQuery(form).attr("id", "pdf-form").attr("name", "pdf-form").attr("class", "pdf-form").attr("target", "_blank");
    jQuery(form).attr("action", "/Controller/OpenPDF").attr("method", "post").attr("enctype", "multipart/form-data");
    return false;

You need to create a form to post your data, append it your dom, post your data and remove the form your document body.

However, form post wouldn't post data to new tab only on EDGE browser. But a get request works as it's just opening new tab with a url containing query string for your action parameters.

How To Open PDF File In New Tab In MVC Using C#, First, create a new project of MVC from File -> New -> Project. ASP.NET. Step 2. Select ASP.NET Web Application (.Net Framework) for creating� Hi is there any option to set to opening another pdf document (1 is opened and i opening another one) in new window instead of opening in new tab in same window? Correct answer by jane-e Adobe Community Professional

How to show PDF in new browser tab using, But this code is not working and instead of downloading .pdf file, .aspx is downloading. I have also tried following code: Hide Copy Code. string� i have a webform where i show the pdf filename in a linkbutton i.e. earlier uploaded by an user . i want when user click that link where pdf file name show that should be open in new window or a new tab. i hv done it bt it shows in same window problem is the user have to click back button of browser . and i written in onclick of link button.

Open (Show) PDF File in new Browser Tab (Window) in ASP.Net, Open (Show) PDF File in new Browser Tab (Window) in ASP.Net (show) PDF File in new Browser Tab (Window) in ASP.Net using C# and VB.Net. embed += "If you are unable to view file, you can download from <a href� Scroll down and click the PDF documents option. Change the "Download PDF files instead of automatically opening them in Chrome" option from the off position (grey) to the on position (blue). Close the Settings tab and restart your computer. Firefox. Open Firefox; Click the menu button and select Options. Within the Options window, click

Show PDF in browser instead of downloading (ASP.NET MVC , If I want to display a PDF file in the browser instead of downloading a return null;. } var contentDispositionHeader = new System.Net.Mime. Upload, Edit, Sign & Export PDF Forms Online. No Installation Needed. Try Now!

  • You could try content-disposition: inline instead of attachment - See this article
  • this article might help you…
  • The first step im interested to know more. The second step is not practical in my program. bcz i cannot sent the original path to it. Using the first step can i redirect the file to another window?
  • You can not open a new window from server side. You will have to open the download page in a new window, and in that window use TransmitFile to return the file to the user.
  • what does your link look like? Why can't you add a target to it? You can add it with JavaScript if for some reason you can't change the a tag's source (e.g. it's generated for you)
  • You can serverside like this. Hyperlink hyper = new HyperLink();hyper.NavigateUrl="PDFViewer.aspx"; hyper.Attributes.Add("target","_blank");
  • Unfortunately, this only works if you have an actual file stored somewhere. If you have a byte array that has been generated for example, there is no 'path' - rendering Response.TransmitFile useless. At least that's what I'm running into.
  • How will i call that downloading file into this?? that's my problem.
  • I should create it for reading and later it can be saved too. The problem is i cannot give the original name of the file or path too with the file. So i must do the above step to download it and then open it with another name.
  • Can you make a temp copy on the server?
  • I tried this method and it works really well, thanks :)
  • Your C# code runs on the server. Therefore, Process.Start starts a process on the server, not your computer. It is fundamentally impossible for you to start a process directly on the client.
  • Thanks, Works for me.