Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Access Error.

Status
Not open for further replies.

nikhilparchure

Programmer
Oct 6, 2001
121
AU
Experiencing a file access exception saying that "The source is currently in use."

Need to handle this..
i.e. : if the file is accessed by some other resource than do not process the file.

How would I do it in C#

Regards
Nikhil

 
The FileShare enumeration is to define whether two processes can simultaneously access from the same file. For example, if a file is opened and FileShare.
Use it combination with FileAccess to grants permissions.
For example a file with FileShare.None will decline the sharing of the file. Any request to open the file (by this process or another process) will fail until the file is closed.
-obislavu-
 
If the other process has opened the file with it's sharing set to "Deny All", there's nothing you can do, as the operating system enforces this.

But try Obislavu's ideas -- maybe the other process has it set to "Share All".

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Thanks Guys ,
As chiph said , that was precisely the precise problem I had faced.
Had a while loop which was scanning all the files in a particular directory, but If any of the file were to be in the "DENY ALL" mode the process would come out of the while loop, since an IO exception was raised and caught.
I had to re-enter the while loop to process the remaining files.
For this I put the try-catch handler inside the while loop which helped in the re-processing of the leftover files.

Anyways thanks for the advice.
I am always able to wiggle out a solution when I come to tek-tips.

Regards
Nikhil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top