Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > AsyncUpload > The process cannot access the file because it is being used by another process.

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

Feed from this thread
  • Posted on Feb 6, 2012 (permalink)

    Good Day 
     
    i am using a AsyncUpload(telerik), i am in a point where i am supposed to save the File to a certain Folder. 


    First i check if the directory exist 
     
     
    Dim baseDire As String = Server.MapPath("~/MyFILES/")
    If IO.Directory.Exists(baseDire & Request("Req_ID").ToString()) = False Then
                   IO.Directory.CreateDirectory(baseDire & Request("Req_ID").ToString())
               End If

     
    Because i am doing multiple Upload  , i will have to loop through the items of the Upload control and save to a folder. 


    For Each file As UploadedFile In UploadPropDoc.UploadedFiles
                  Dim bytes(file.ContentLength - 1) As Byte
                  file.InputStream.Read(bytes, 0, file.ContentLength)
                   'Save the File to the disk
                  file.SaveAs(baseDire + file.GetName())
              Next



    Now when ever i debug this , when it comes to this line 


    file.SaveAs(baseDire + file.GetName())
     


    i get an Error 
     
     The process cannot access the file because it is being used by another process 
     


    I have removed the Readonly in the Folder that it supposed to write to and gave everyone permission , but still the error persist.


    Thanks


    Reply

  • Answer jumpstart Master avatar

    Posted on Feb 8, 2012 (permalink)

    Vuyiswa,

    Since you did not post your entire code, it's a bit hard to know what is locking the file. But, It looks like you may not be properly creating and releasing the stream that you're feeding to file.InputStream. This process is covered very comprehensively in the IOException when saving forum thread.

    If you cannot find the solution in this thread, I'd suggest posting your entire code for review.

    Hope this helps!

    Reply

  • Posted on Feb 8, 2012 (permalink)

    hi jumpstart

    Thanks , the issue was that i was not closing the Stream. One other thing is that i thought i had to create the file and save it to a certain folder myself , i later looking at the documentation i realised that every postback it post the uploaded files to the "TargetFolder" which is very cool. 

    Thanks


    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > AsyncUpload > The process cannot access the file because it is being used by another process.
Related resources for "The process cannot access the file because it is being used by another process."

ASP.NET AsyncUpload Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]