Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hello!

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
Updated 22-Apr-11 0:41am
v2

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#.
 
Share this answer
 
Comments
Olivier Levrey 22-Apr-11 10:01am    
Voted 5.
Nish Nishant 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.
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)
            {
                outf.WriteByte((byte)a);
            }
            inf.Close();
            inf.Dispose();
            outf.Close();
            outf.Dispose();
 
Share this answer
 
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
 
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