Click here to Skip to main content
11,926,429 members (59,868 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#

So there is a .gdb file, which is being used by an application. I would like to read from it while it is being used. But of course I can't. I tried copying it, and then accessing, but with File.Copy it threw an exception "File is being used by another process" again. But by simply copying this file in windows (ctrl+c) and pasting (ctrl+v) it worked. So what's the difference between File.Copy and the normal ctrl+c ctrl+v method?
And how could I implement this? I have read about Shadow Copy, but I didn't find any C# code.
Posted 22-Apr-11 1:40am
Edited 22-Apr-11 1:41am
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If the file is opened with an exclusive lock (meaning it was not shared for read), then you will not be able to use any of the regular APIs to open the file. There may be lower level solutions that can read directly off the disk, but I don't think any of them are practical solutions from C#.
Olivier Levrey 22-Apr-11 10:01am
Voted 5.
Nishant Sivakumar 22-Apr-11 10:02am
Thank you, Olivier.
velvet7 22-Apr-11 12:47pm
But then how is it possible that I can copy with ctrl+c, but I can't with File.Copy? What is the difference between this two thing? I thought they are the same.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

All right, I found a solution:
FileStream inf = new FileStream("path1", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            FileStream outf = new FileStream("path2", FileMode.Create);
            int a;
            while ((a = inf.ReadByte()) != -1)
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try this, This is similar type of question which was asked on CP.
IOException: The Process can not access the file filename[^]
Thought this might be helpful

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 23 Apr 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100