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

5 posts, 1 answers
  1. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 06 Feb 2012 Link to this post

    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


  2. Answer
    jumpstart
    jumpstart avatar
    479 posts
    Member since:
    Nov 2011

    Posted 08 Feb 2012 Link to this post

    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!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vuyiswa Maseko
    Vuyiswa Maseko avatar
    187 posts
    Member since:
    Jan 2010

    Posted 08 Feb 2012 Link to this post

    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


  5. Alisa
    Alisa avatar
    1 posts
    Member since:
    Oct 2012

    Posted 03 Oct 2012 Link to this post

    Long Path Tool helped me in this situation. http://PathTooDeep.com
  6. Rowi
    Rowi avatar
    1 posts
    Member since:
    Oct 2012

    Posted 12 Oct 2012 Link to this post

    I have a same problem of you, but long path tool help me in this situation. So you can download a latest version of “Long Path Tool" for solve this problem.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017