Downloading PDF will not open, must save

Hi,

Response.Clear();

Response.AddHeader("Content-Disposition", "attachment; filename=" + oFile.Name);

Response.AddHeader("Content-Length", oFile.Length.ToString());

Response.ContentType = "application/octet-stream";

Response.WriteFile(oFile.FullName);

Response.End();

The problem here is when a pdf is to be downloaded, it will not open directly in the browser. You must save the file first and then you get a new dialog asking you if you want to open the file. Other file types work correctly, only PDF's are causing me grief.

I noticed when downloading a word doc, the Open dialog option was not displayed. Is there anyway to force the display of only Save or Cancel. This problem will create many support calls.




Answer this question

Downloading PDF will not open, must save

  • Kennon2005

    Try this :

    It is pretty similar to what you have

    Response.ContentType = "application";

    Response.Clear();

    Response.BufferOutput = true;

    Response.AddHeader("content-disposition", "inline; filename =" + filename); // Difference here

    Response.OutputStream.Write(blob, 0, blob.Length - 1);

    Response.Flush();

    Thanks,

    Harsimrat


  • Downloading PDF will not open, must save