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

Last post 06-25-2009, 9:38 AM by cutechat. 6 replies.
Sort Posts: Previous Next
  •  06-24-2009, 10:51 AM 53468

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

    I'm uploading the files using the ajax uploader.  Elsewhere in my code (on another page), I'm attempting to move the files (using File.Move) that have been uploaded to another directory.  This won't happen until a certain amount of time has passed.  Only after this time can I move the files (as of right now, I've waited 25 mins and I still can't move the files, but the files will eventually move)
     
    Here is how I have the uploader set up:
    <CuteWebUI:Uploader runat="server" ID="up1" InsertButtonID="upBtn" MultipleFilesUpload="true"
    EnableViewState="false" onfileuploaded="up1_FileUploaded"
    AutoUseSystemTempFolder="false" onuploadcompleted="up1_UploadCompleted"></CuteWebUI:Uploader>

    protected void up1_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)
    {
    Uploader uploader = (Uploader)sender;
    string path = Server.MapPath("~/uploads");

    if (File.Exists(path + "\\\\" + filename))
    {
    //rename the file

    filename = Images.RenameFile(path, filename);
    args.CopyTo(path +
    "\\\\" + filename);
    }
    else
    {
    args.CopyTo(path + "\\\\" + filename);
    }
    }

    In the up1_UploadCompleted, all I do is take the filenames that were uploaded and put them into a database.
     
    So...what's the deal?
  •  06-24-2009, 11:34 AM 53469 in reply to 53468

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

    The only way I could get the file to move was to reboot the computer.
  •  06-24-2009, 1:08 PM 53474 in reply to 53469

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

    Hi,
     
    Can you move the file after restart the IIS ?
     
    Regards,
    Terry
  •  06-24-2009, 1:33 PM 53477 in reply to 53474

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

    I will have to test that. 
     
    I did go to lunch and now that an hour as passed I was able to move the file.  I guess the process that had a stranglehold on the file timed out.
     
    EDIT:  Yes, restarting IIS released the process that has all files recently uploaded locked down.
  •  06-24-2009, 1:45 PM 53479 in reply to 53477

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

    Hi,
     
    I think you can test the uploader on a new project.
     
    Do not use any http modules or third party products.
     
    You can just use our samples , and test the Move function.
     
    Maybe there's some special condition caused the uploader not able to release the file stream.
     
    Regards,
    Terry
     
  •  06-24-2009, 2:03 PM 53481 in reply to 53479

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

    modeuls are:

    <httpModules>

    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

    <add name="CuteWebUI.UploadModule" type="CuteWebUI.UploadModule,CuteWebUI.AjaxUploader"/>

    <!-- remove unnecessary http modules for faster pipeline -->

    <remove name="PassportAuthentication" />

    <remove name="FileAuthorization" />

    <remove name="WindowsAuthentication" />

    <!--<remove name="ErrorHandlerModule" /> not sure if I use this or not 2/3/9-->

    </httpModules>

    This is a plain .net webform that is using a masterpage.  I posted all of the relevant code.
     
    Is there a way to force the fileuploader to close the stream?
  •  06-25-2009, 9:38 AM 53519 in reply to 53481

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

    Hi,
     
    I have checked the code again.
     
    After upload ,before the FileUploaded event be fired, the file will be renamed once.
     
    So the file must be released.
     
    I don't know why you get the file locked issue.
     
    Please try the UploadType property , set to IFrame,Silverlight,Flash and try again.
     
    Regards,
    Terry
View as RSS news feed in XML