Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am trying to copy a file from my local folder to the network folder.
When i copy a file to the network for first time i am able to copy the file, if i try to copy the same file again i get a error saying " the file is being used by another process".
Do i need to dispose or flush anything before performing the same copy operation again.


Thanks and Regards
Ron
Posted
Comments
ZurdoDev 13-Apr-12 8:21am    
Are you talking about doing this through code or manually?

Yes, you have to close the source stream.
You can use:
C#
using (Stream sourceStream = File.Open("mySourceFile.data"))
{
  using (Stream targetStream = File.Create("myTargetFile.data"))
  {
    targetSteam.CopyFrom(sourceStream);
  }
}

(The "using" will ensure that "dispose" is called when the block is left, equal whether an exception occurred or not)

(See here for the "CopyFrom" extension method: "Copy a Stream with Progress Reporting"[^])
 
Share this answer
 
Please pick one of the link from C# the file is being used by another process [^]

Hope it helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900