1

This is in asp.net. I am creating pdf file with reference to the inputs from users. This pdf file is saved on folder on server. Now this is file can be shown in browser using response.redirect. But I want to show the Save file dialog (like we get while downloading exe from websites) to the user for downloading and saving the same file in local hard disk instead of opening it in browser. How can i do that??

1

2 Answers 2

2

Setting Response.ContentType = "application/octet-stream"; usually works for me. I also use Response.BinaryWrite as well. There IS a mime type application/pdf (MIME Type Detection in Windows Internet Explorer), so you might give that a try too.

Here's an example using application/pdf from Microsoft (How To Write Binary Files to the Browser Using ASP.NET and Visual C# .NET)

private void Page_Load(object sender, System.EventArgs e)
{
  //Set the appropriate ContentType.
  Response.ContentType = "Application/pdf";
  //Get the physical path to the file.
  string FilePath = MapPath("acrobat.pdf");
  //Write the file directly to the HTTP content output stream.
  Response.WriteFile(FilePath);
  Response.End();
}
Sign up to request clarification or add additional context in comments.

Comments

0

to enable the save as box on download time is the about browser configuration not about the code ..... try this configuration of chrome browser ..Goto setting > show advance setting > in Downloads enable check box of "Ask where to save each file before downloading"

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.