title: FileNotFoundException IIS7
body: <p>I have a C# Web app that runs perfectly fine in VS2010, but when deployed to an IIS7 server, returns the "image not found icon". </p>
  
  <p>The piece of code in question essentially grabs a thumbnail of an image on a network shared location, manipulated and then pushed back out to the webpage.</p>
  
  <p>The web server sits on the same network as the files it is trying to access. All users that access this webpage are all on the same local intranet.</p>
  
  <p>The application is a stored list of network saved resources that are categorized in one way or another.</p>
  
  <p>When I deploy the application, it gives the above two errors that I find in my Application Log. I feel that this is a file permissions error and that the two errors are linked, but I do not know where to change the permissions for this to make the application work properly.</p>
  
  <pre><code>Exception information: 
  Exception type: FileNotFoundException 
  Exception message: T:\Published\Generic.jpg
  </code></pre>
  
  <p>However, if I take "T:\Published\Generic.jpg" and plug it into my address bar of IE. It loads the image.</p>
  
  <p>The section of code that handles the image is this:</p>
  
  <pre><code>System.Drawing.Image img;
  img = System.Drawing.Image.FromFile(MapPath(Request.QueryString["File"].ToString()));
  </code></pre>
  
  <p>I've tried it with both with and without the MapPath method.</p>
  
  <p>I try to debug the application, but because it is working in VS2010, it is not throwing the exception so I don't know why it is being tossed on the IIS server.</p>
  
  <p>Entire Stack Trace as requested:</p>
  
  <pre><code>Event code: 3005 
  Event message: An unhandled exception has occurred. 
  Event time: 13/02/2012 4:16:26 PM 
  Event time (UTC): 13/02/2012 11:16:26 PM 
  Event ID: 1f01693f71a2443790a8d83ba06a88a4 
  Event sequence: 12 
  Event occurrence: 1 
  Event detail code: 0 
  
  Application information: 
  Application domain: /LM/W3SVC/2/ROOT-3-129736485835718008 
  Trust level: Full 
  Application Virtual Path: / 
  Application Path: C:\inetpub\wwwroot\
  Machine name: XXXXXX
  
  Process information: 
  Process ID: 10768 
  Process name: w3wp.exe 
  Account name: IIS APPPOOL\ASP.NET v4.0 
  
  Exception information: 
  Exception type: FileNotFoundException 
  Exception message: T:\Published\Generic.jpg
  at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
  at imagedrawer.Page_Load(Object sender, EventArgs e)
  at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  
  
  
  Request information: 
  Request URL: http://localhost/imagedrawer.aspx?File=T:\Published\Generic.jpg 
  Request path: /imagedrawer.aspx 
  User host address: ::1 
  User:  
  Is authenticated: False 
  Authentication Type:  
  Thread account name: IIS APPPOOL\ASP.NET v4.0 
  
  Thread information: 
  Thread ID: 64 
  Thread account name: IIS APPPOOL\ASP.NET v4.0 
  Is impersonating: False 
  Stack trace:    at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
  at imagedrawer.Page_Load(Object sender, EventArgs e)
  at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  
  
  Custom event details: 
  </code></pre>
  
  <p>Contents of imagedrawer.aspx:</p>
  
  <pre><code> System.IO.MemoryStream ms = new System.IO.MemoryStream();
          System.Drawing.Image img;
  
          img = System.Drawing.Image.FromFile(MapPath(Request.QueryString["File"].ToString()));
  
  
          if (img.Height &gt; 80 || img.Width &gt; 80)
          {
              System.Drawing.RectangleF RF = new System.Drawing.RectangleF();
              RF.X = 0;
              RF.Y = 0;
              RF.Height = (img.Height &lt; 80) ? img.Height : 80;
              RF.Width = (img.Width &lt; 80) ? img.Width : 80;
              System.Drawing.Bitmap bmthumb = (System.Drawing.Bitmap)img.Clone();
              System.Drawing.Bitmap bmCrop = bmthumb.Clone(RF, bmthumb.PixelFormat);
              img = (System.Drawing.Image)bmCrop;
          }
          img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  
  
          Response.Clear();
          Response.AddHeader("Content-Disposition", "attachment; filename=" + Request.QueryString["File"].ToString());
          Response.AddHeader("Content-Length", ms.ToArray().Length.ToString());
          Response.ContentType = "image/jpeg";
          Response.BinaryWrite(ms.ToArray());
          Response.End();
          img.Dispose();
  </code></pre>