Trey Nuckolls
Trey Nuckolls

Reputation: 591

Assuredly simple C# file saving issue

We have a custom built web application built on ASP (2.0 it looks like) using C#. We recently moved it from an IIS6 environment to an IIS7. We have run into an issue where a page set up to view images that had been retrieved via a search is throwing an error. The code takes a copy of the image file and puts it into a work directory renaming the copy to the user's name.

bmpList[0].Save("c:\\inetpub\\wwwroot\\SiteName\\Work\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);

I know that the wwwroot is no longer a valid directory in the path so I changed it to...

bmpList[0].Save("c:\\inetpub\\SiteName\\Work\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);

Saved the file, did and IIS restart and cleared my browser cache and still receive an error...

A generic error occurred in GDI+. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.

Source Error: 
Line 180:                       
Line 181:                    //bmpList[0].Save("c:\\pi\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);
Line 182:                    bmpList[0].Save("c:\\inetpub\\wwwroot\\SiteName\\Work\\" + ((ImageUser)Session["ImageUser"]).Username + ".TIF", info, encParams);
Line 183:
Line 184:                    for (int a = 1; a < numFiles; a++)


Source File: c:\inetpub\Sitename\SiteApp\View.aspx.cs    Line: 182 

Stack Trace: 
[ExternalException (0x80004005): A generic error occurred in GDI+.]
System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) +615209
View.Page_PreRender(Object sender, EventArgs e) in c:\inetpub\SiteName\SiteApp\View.aspx.cs:182
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnPreRender(EventArgs e) +11056766
System.Web.UI.Control.PreRenderRecursiveInternal() +108
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394

It seems like a fairly straightforward thing but for some reason it is not updating (the path in the error remains exactly the same). What am I missing?

Upvotes: 3

Views: 169

Answers (2)

Trey Nuckolls
Trey Nuckolls

Reputation: 591

So oddly enough the answer is actually as simple as it looks... almost. Changing... c:\inetpub\wwwroot\SiteName\Work\ to... c:\inetpub\SiteName\Work\ worked. Why it was continuing to give me the same error from the browser after I changed the code on the .cs file was that the IP that they had bound to the site still belonged to a previous version of the machine so DNS was routing me over to that box instead. All said it ended up I was on the wrong OSI model layer. I only discovered it when I went to build a test version on the same box and went to unbind the IP from the broken site and bind it to my second test site and I found that the IP I wanted wasn't an option (so it must have been manually entered). Live and learn. Thanks for the input and advise.

Upvotes: 0

AR5HAM
AR5HAM

Reputation: 1304

Almost all the time (i.e 99.9999% of the times), when using GDI, 'a generic error occured' means that the directory you are trying to save to doesn't have the proper permissions. Typically, you need to make sure that directory is allowing asp.net to modify files. Did you check the permission on the directory you are trying to save the files to?

Upvotes: 1

Related Questions