views:

37

answers:

2

Hi,

I've got ASP.NET intranet application written in VB. It gets a file from the user, and then depending on a few different cases it may create a few copies of the file as well as move the original.

Unfortunately I've come across a case where I get this error:

Exception Details: System.IO.IOException: The process cannot access the file 
'\\some\dir\D09_03_5_180_0.000-6.788.png' because it is being used by 
another process.

Which is thrown by My.Computer.FileSystem.CopyFile. And that's fine that it's being used by another process - it may still be saving/downloading from the user or trying to copy while another thread(?) is copying, I don't really care about that, what I want to know:

Is there any way that I can tell VB to wait to copy (also move) the file until the file is no longer in use?

Thanks

A: 

Hmm... not directly. What most implementations are doing, is making a retry of copying the file, with a small timeframe (some seconds)

if you want to make a nice UI, you check via Ajax, if the copying process went well.

cRichter
A: 

Well, it turns out that waiting would not work in this case:

When trying to copy a file you cannot copy a file from one location to the same location or it will throw an error (apparently). Rather than just pretending to copy the file, VB actually tries to copy the file and fails because the copy operation is trying to copy to the file it's copying from (with overwrite:=True at least).

Whoops!

Wayne Werner