Click here to Skip to main content
14,825,162 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to resolve viewing of PDF issue in asp.net with c#. PDF File is there in the configured path. PDF is unable to view for some PDF Files.
Getting below error
File does not begin with %PDF

What I have tried:

My code is as below:
string path = dict["FileName"].ToString();
                       WebClient client = new WebClient();
                       Byte[] buffer = client.DownloadData(path);

                       if (buffer != null)
                       {
                           Response.ContentType = "application/pdf";
                           Response.AddHeader("content-length", buffer.Length.ToString());
                           Response.BinaryWrite(buffer);
                       }

                       Response.End();
Posted
Updated 6-Dec-20 17:35pm
v4

1 solution

Ok, but the PDF standard says that a PDF file begins with %PDF (and then, iirc), a "-x.y" where x.y represent the version of the PDF language the file was built with.

Given that, are you really sure these 'other' files that give you errors ARE PDF's ? .. I'd be adding a check to my code logic to reject non PDF files
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900