Cannot access the file because it is being used by another process.

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

Cannot access the file because it is being used by another process.

Guest-1051
Hi, I've got the files to upload into my DB just fine, but after they upload NeatUpload tries to delete the temp files and fails. The error is: The process cannot access the file 'C:\workspace\OGC.RFPUploadSite.Web\OGC.RFPUploadSite.Web\app_data\NeatUpload_Temp\8a3bf3126c794d0ebc5946abeab9fc17.config' because it is being used by another process. This is thrown here: public override void Dispose() { if (log.IsDebugEnabled) log.DebugFormat("In Dispose(): TmpFile.FullName = {0}", TmpFile.FullName); if (TmpFile.Exists && TmpFile.FullName == (new FileInfo(tmpFileName)).FullName) { log.DebugFormat("Calling TmpFile.Delete()"); TmpFile.Delete(); <---- IOException thrown here. } } Here is the offending code: protected void UploadFileButton_Click(object sender, EventArgs e) { if (IsValid && InputFile1.HasFile) { RFPDataClassesDataContext db = new RFPDataClassesDataContext(); FileTable file = new FileTable(); file.Created = DateTime.Now; byte[] buffer = new byte[InputFile1.ContentLength]; using (MemoryStream ms = new MemoryStream()) { int read; while ((read = InputFile1.FileContent.Read(buffer, 0, buffer.Length)) > 0) { ms.Write(buffer, 0, read); } file.DataField = ms.ToArray(); ms.Close(); } file.MimeType = InputFile1.ContentType; file.FileName = InputFile1.FileName; file.FileHash = InputFile1.GetHashCode().ToString(); file.UserId = 1; db.FileTables.InsertOnSubmit(file); db.SubmitChanges(); InputFile1.Dispose(); // Not sure if I need to do this, but the behavior is the same either way. } } I'm not really sure what's going on or what's wrong. Any help would be appreciated.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot access the file because it is being used by another process.

Guest-1051
Ak! that looks like it's hard to read... Hrm.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Cannot access the file because it is being used by another process.

Guest-1051
Nevermind, I figured it out. I wasn't calling InputFile1.FileContent.Close(); I guess I should have searched a little harder in the forums. :-P
Loading...