0

I want to open a report in a new tab which is a pdf file. I want to do it without saving this file in my computer. I am using asp.net MVC 5. On the given code, when I click the Export Report button it just download the pdf. But I want to view it first in a new tab then download.Here is my code:

Controller:

public ActionResult ExportLogReport()
    {
        List<LogDetails> allCustomer = new List<LogDetails>();
        allCustomer = aSaveLogMasterManager.GetAllLogDetails();


        ReportDocument rd = new ReportDocument();
        rd.Load(Path.Combine(Server.MapPath("~/Reports"), "CrystalReport1.rpt"));

        rd.SetDataSource(allCustomer);

        Response.Buffer = false;
        Response.ClearContent();
        Response.ClearHeaders();


        Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
        stream.Seek(0, SeekOrigin.Begin);
        return File(stream, "application/pdf", "LogDetailsList.pdf");
    }

View:

<div>
    <a href="@Url.Action("ExportLogReport","SaveLogMaster")" target="_blank">Export Report</a>
</div>
habib
  • 2,366
  • 5
  • 25
  • 41
Asad Khan
  • 1
  • 1
  • Have you tried what it says on [this page](https://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html) – Pietro Nadalini Jul 27 '18 at 16:40
  • look if i save this file then i can easily open it from my pc using js. but i dont to store first. First i want to view and u r given page refers how i open stored file – Asad Khan Jul 27 '18 at 16:45
  • 1
    As far as I've known you can't show a file without saving it first – Pietro Nadalini Jul 27 '18 at 16:52
  • Your requirement is kinda weird. A pdf file cannot be viewed in the client computer without saving it somewhere in the user's disk. So when you are opening the file in a new tab the file is already downloaded - just not in the _downloads_ folder. – Sнаđошƒаӽ Jul 27 '18 at 17:51
  • This has already been answered here: https://stackoverflow.com/questions/14714486/opening-a-pdf-file-directly-in-my-browser One way to prompt the browser to display inline is to drop the filename from the response; another is to use `"Content-Disposition","inline"` - see answers below the accepted one in the question I've linked to. – Jude Fisher Jul 27 '18 at 17:56
  • in this way i can view it but when try to download from viewer it doest not dw as pdf format . what i do for it ? – Asad Khan Jul 27 '18 at 18:30

0 Answers0