Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 22-Apr-11 1:40am
velvet71.1K
Edited 22-Apr-11 1:41am
v2
Rate this: bad
good
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#.
  Permalink  
Comments
Olivier Levrey at 22-Apr-11 10:01am
   
Voted 5.
Nishant Sivakumar at 22-Apr-11 10:02am
   
Thank you, Olivier.
velvet7 at 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
good
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)
            {
                outf.WriteByte((byte)a);
            }
            inf.Close();
            inf.Dispose();
            outf.Close();
            outf.Dispose();
  Permalink  
Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 5,130
1 DamithSL 4,237
2 Maciej Los 3,700
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,846


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 23 Apr 2011
Copyright © CodeProject, 1999-2014
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