Home view a PDF without downloading it
Reply: 1

view a PDF without downloading it

Sergio Dalla Valle
1#
Sergio Dalla Valle Published in 2017-11-13 12:43:55Z

Now my controller returns the file in this way:

[HttpGet]
public IActionResult document(int id)
{
      var byteArray = db.instances.Where(c => c.id == id).FirstOrDefault().document;    
      if (byteArray == null)
      {
            return null;
      }
      Stream stream = new MemoryStream(byteArray);

      return File(stream, "application/pdf", "document.pdf");
}

Client:

<a href="@Url.Action("document", "Catalog", new { id = Model.id })" target="_blank">Open pdf</a>

I would like to view the PDF without downloading it, how can I do it?

Renan Vasconcelos
2#
Renan Vasconcelos Reply to 2017-11-13 12:50:10Z

You should append a header to your response saying it should display it instead of downloading

This way:

[HttpGet]
public IActionResult document(int id)
{
      var byteArray = db.instances.Where(c => c.id == id).FirstOrDefault().document;    
      if (byteArray == null)
      {
            return null;
      }
      Stream stream = new MemoryStream(byteArray);

      Response.AppendHeader("content-disposition", "inline; filename=file.pdf");
      return File(stream, "application/pdf", "document.pdf");
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.557923 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO