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?

[Webinar] Streamline your web hosting managementRegister Today

infotechelgConnect With a Mentor Author 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.
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...
All Courses

From novice to tech pro — start learning today.