This is a migrated thread and some comments may be shown as answers.

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

4 Answers 240 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Vuyiswa
Top achievements
Rank 2
Vuyiswa asked on 06 Feb 2012, 02:13 PM
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


4 Answers, 1 is accepted

Sort by
0
Accepted
Richard
Top achievements
Rank 1
answered on 08 Feb 2012, 03:42 PM
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!
0
Vuyiswa
Top achievements
Rank 2
answered on 08 Feb 2012, 10:39 PM
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


0
Alisa
Top achievements
Rank 1
answered on 03 Oct 2012, 05:51 PM
Long Path Tool helped me in this situation. http://PathTooDeep.com
0
Rowi
Top achievements
Rank 1
answered on 12 Oct 2012, 03:52 PM

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.

Tags
AsyncUpload
Asked by
Vuyiswa
Top achievements
Rank 2
Answers by
Richard
Top achievements
Rank 1
Vuyiswa
Top achievements
Rank 2
Alisa
Top achievements
Rank 1
Rowi
Top achievements
Rank 1
Share this question
or