1

I want to display a PDF file and it working but when i'm clicking the saveing button it ask me to save a aspx page and not PDF file? this is my code:

string path = CanvasWritingStepImages._pdfName;
        WebClient client = new WebClient();
         Byte[] buffer = client.DownloadData(path);

          if (buffer != null)
          {
              //content-disposition
              Response.ContentType = "application/pdf";
              Response.AddHeader("content-length", "attachment ;filename=Formulike.PDF");
             Response.BinaryWrite(buffer);


          }
          else
          {
              logger.Error("Buffer was Null!");
          }

how i can make it a PDF file when i'm saving it? may be to open in new tab? if so, how can i do it?

2 Answers 2

1

Try replacing this line

Response.AddHeader("content-length", "attachment; filename=Formulike.PDF");

With this

Response.AddHeader("Content-Disposition", "attachment; filename=Formulike.pdf");

You can also use

Response.AddHeader("Content-Disposition", "inline; filename=Formulike.pdf");

Changing from attachment to inline will cause the pdf to be displayed in the browser window rather than prompt with a save/open dialog

Sign up to request clarification or add additional context in comments.

1 Comment

is there a way to do it both? display and download?
0

Thanks to @kelix i found a way to make it both download PDF and show PDF

 Response.AddHeader("Content-Disposition", "inline; filename=Formulike.pdf");
              Response.AddHeader("content-length", "attachment ;filename=Formulike.PDF");

the "inline" is important.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.