nz881 nz881 - 1 year ago 103
ASP.NET (C#) Question

How to VIEW files on

I am trying to view files from a folder in I have tried using the "Response" class and its many functions to view files but so far I have been unsuccessful. Mostly using the Response class allows me to download the files but not view them in the browser. Most of what I have seen online suggests the same thing which is to use this bit of code:

string fileName = "Myfile.pdf";
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "inline; filename="+fileName);

But again, this only allows me to download the file and not view it in the browser.

Any suggestions on how I can do this?

Answer Source

This is what works for me:

        Response.AddHeader("Content-Length", binaryFile.Length.ToString(CultureInfo.InvariantCulture));
        //Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", title)); // save file as attachment
        Response.AddHeader("Content-Disposition", string.Format("inline; filename={0}", title)); // display inline in browser
        Response.AddHeader("Content-Type", "application/pdf");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download