Problem with creating PDF on Production server

I have an application that creates a PDF and then stores it in a database. On my local machine everything works great, but it fails with the following error when on the production server.  Line 66 is

using (FileStream fs = File.Create(@"Eval" + DaRec + ".pdf"))

Open in new window


System.UnauthorizedAccessException: Access to the path 'C:\Windows\SysWOW64\inetsrv\Eval1200.pdf' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) at System.IO.File.Create(String path) at GeneratePDF.Page_Load(Object sender, EventArgs e) in c:\Projects\appcreate\GeneratePDF.aspx.cs:line 66

Here is the complete code.

 using (MemoryStream myMemoryStream = new MemoryStream())
                {
                    try
                    {

                        Document myDocument = new Document(PageSize.A1, 10f, 10f, 10f, 0f);
                        PdfWriter myPDFWriter = PdfWriter.GetInstance(myDocument, myMemoryStream);
                        myDocument.Open();
                        WebClient wc = new WebClient();
                        string htmlText = wc.DownloadString("http://Prod40202/appcreate/GeneratePDF/CreatePDF.aspx?pid=" + DaRec);
                        Response.Write(htmlText.Replace("\r", "").Replace("\n", "").Replace("  ", ""));

                        List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), null);

                        for (int k = 0; k < htmlarraylist.Count; k++)
                        {

                            myDocument.Add((IElement)htmlarraylist[k]);
                        }
                        myDocument.Close();
                        byte[] content = myMemoryStream.ToArray();
                        //    document.Close();
                        using (FileStream fs = File.Create(@"Eval" + DaRec + ".pdf"))
                        {

                            fs.Write(content, 0, (int)content.Length);
                            var p5 = ctx1.tblAttachments.SingleOrDefault(u => u.AttachmentID == RecID);
                            if (p5 != null)
                            {
                                p5.DocName = "PayEval" + DaRec + ".pdf";
                                p5.DocType = "pdf";
                                p5.DocByteSize = Convert.ToInt32(fs.Length);
                                p5.DocBinary = content;
                                p5.DateCreated = DateTime.Now;
                                ctx1.SaveChanges();
                                Response.Redirect("OpenAttachment.aspx?pid=" + RecID);

                            }

                        }
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.ToString());
                    }
                }

Open in new window

NickMalloySystems LeadAsked:
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.

Mandeep SinghDatabase AdministratorCommented:
Hi
It is something related to Permissions on particular folder:C:\Windows\SysWOW64\inetsrv\
try
righ click the folder - properties - security then give access everyone user.
or

Refer this:
http://stackoverflow.com/questions/19724297/asp-net-getting-the-error-access-to-the-path-is-denied-while-trying-to-upload
0

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
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.