PDF Errors when opening PDFs with .NET

On a server, I have several PDF files. When I go to the server and open the PDFs, I do so with no problems. When I try to open the file through the Web site, I get an Acrobat error:

"There was an error opening this document. The file is damaged and could not be repaired."

I am opening these files using the attached code. Note also that some PDFs open fine and others don't; but, the all open fine if they're opened directly by double clicking on the PDF on the server.

Let me know if you need more information.

Please help. This is extremely urgent.
NameValueCollection nvc = Methods.GetQueryString(); 
        string fn = nvc["fn"]; 
        string ext = nvc["ext"]; 
        string bucket = nvc["bucket"]; 
        string year = nvc["year"]; 
        string reportType = nvc["report"]; 
        string month = nvc["month"]; 
        string type = nvc["type"]; 
        string fullPath = nvc["fullPath"]; 
        bucket = (!string.IsNullOrEmpty(bucket)) ? bucket.Replace("$", "&") : bucket; 
        fullPath = (!string.IsNullOrEmpty(fullPath)) ? fullPath.Replace("$", "&") : fullPath; 
        string[] fnSplit = fn.Split('.'); 
        string newName = null; 
        string folderPath = null; 
            if (bucket.ToUpper() == "PARTNER CENTRAL") 
                newName = fn + "_" + month + year + "_" + reportType + ".pdf"; 
            else newName = fn + ext; 
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + newName); 
            folderPath = ServerConfigManager.GetPartnerDocPath() + Methods.CheckSession("SiteAbbr") + "\\" + bucket + "\\"; 
            if (bucket == "PARTNER CENTRAL") folderPath += year + "\\" + reportType + "\\" + month + "\\" + fn; 
            else folderPath = fullPath; 
        try { Response.TransmitFile(folderPath); }
        catch { throw; }

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't know if this matters, but try giving the internet_guest account full permissions to the pdf files!
infotechelgAuthor Commented:
meetingexpectations: I compared the permissions of a file that is working to a file that is not working and all permission are set up exactly the same. So, that's not it.

However, I do appreciate you at least attempting to assist me.

I'm a bit disheartened that no one else has any ideas. These file downloads represent about 80% of the project I'm working on and if I can't get this to work, I'm back to square one after months of work.
The other things I would look at is size of the files, try re-naming the ones that don't work to the ones's that work. Are all the values in the querystrings always present. Aprt from that I do not know much...
infotechelgAuthor Commented:
Well, I figured it out. I added Response.End() to a finally { } block in the try/catch block.

I saved a PDF to my desktop, opened it with notepad, and noticed there was some HTML in there.

This still doesn't tell my why some files were opening and some weren't but at least it's working now.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.