File Not Found Exception

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

File Not Found Exception

Ryan
I am trying to use the inputFile control and multiFile control on a page.

Whenever I submit the page I get a System.IO.FileNotFoundException whenver i call MoveTo.  I have tried using the system default temp file location and the app_data temp file location(it exists and has write access).  The application  is running on IIS7.

Here is the code for the inputFile

if (thumbnail.HasFile)
{
     webPath = string.Format("~/resources/{0}/thumbnails/", new object[] { category.Text.ToLower() });
     saveAs = uploadId + "-" + name.Text + thumbnail.FileName.Substring(thumbnail.FileName.LastIndexOf('.'));
     saveTo = this.Page.Server.MapPath(webPath);

     thumbnail.MoveTo(Path.Combine(saveTo, saveAs), MoveToOptions.Overwrite); //System.IO.FileNotFoundException
     responseString += Path.Combine(thumbnail.TmpFile.DirectoryName, thumbnail.FileName) + " Save To: " + Path.Combine(saveTo, saveAs) + "<br />";

     cmd.Parameters["@type"].Value = "thumbnail";
     cmd.Parameters["@path"].Value = webPath + saveAs;
     responseString += "Thumbnail: " + thumbnail.FileName + "<br /><br />";

     cmd.ExecuteNonQuery();
}

Here is the stack trace:

[FileNotFoundException: Unable to find the specified file.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +10543824
   System.IO.FileInfo.MoveTo(String destFileName) +346
   Brettle.Web.NeatUpload.FilesystemUploadedFile.MoveTo(String path, MoveToOptions opts) +184
   Brettle.Web.NeatUpload.InputFile.MoveTo(String path, MoveToOptions opts) +83
   demoProj.Upload2.submit_Click(Object sender, EventArgs e) in Upload2.aspx.cs:167
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

Thanks for your help.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File Not Found Exception

Dean Brettle
Administrator
Put a breakpoint on the call to MoveTo() and see whether it is getting called more than once per postback.  If it is, that might cause the error you are seeing.

--Dean
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File Not Found Exception

Guest-1102
The error is happening on the first call to MoveTo.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: File Not Found Exception

Dean Brettle
Administrator
Please email me (dean at brettle dot com) a small but complete test project that produces the error.

Thanks,
--Dean
Loading...