Copy or read locked/in use files
-
Hi for all! I have some problem, while try to read and copy locked or files witch in use. I try this method, witch work for some file, but the others not :doh: my way:
FileStream fs = null; try { try { fs = File.OpenRead(file); } catch { fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); } } catch { try { string NewFile=File+"_"; Fi.CopyTo(NewFile, true); } catch { try { File.Copy(file, NewFile, true); } catch { } } } } catch (Exception e) { MessageBox.Show("Grrrrrr: "+e.Message); }
I miss somethink, or I need a nother way to figure out windows file locking system. I wait for any ideas.... Thank's for help. -
Hi for all! I have some problem, while try to read and copy locked or files witch in use. I try this method, witch work for some file, but the others not :doh: my way:
FileStream fs = null; try { try { fs = File.OpenRead(file); } catch { fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); } } catch { try { string NewFile=File+"_"; Fi.CopyTo(NewFile, true); } catch { try { File.Copy(file, NewFile, true); } catch { } } } } catch (Exception e) { MessageBox.Show("Grrrrrr: "+e.Message); }
I miss somethink, or I need a nother way to figure out windows file locking system. I wait for any ideas.... Thank's for help.Try to copy first and then open the new file. For example : You have a file "hello.txt". Then you can lock it using FileStream fStream = new FileStream("hello.txt", FileMode.Open); If you try to copy it, it works... File.Copy("hello.txt", "hello_1.txt"); Then just open "hello_1.txt".
-
Try to copy first and then open the new file. For example : You have a file "hello.txt". Then you can lock it using FileStream fStream = new FileStream("hello.txt", FileMode.Open); If you try to copy it, it works... File.Copy("hello.txt", "hello_1.txt"); Then just open "hello_1.txt".
-
Thanks stancrm! It was the first think I try. But some files it not works. Exampl MS Outlook .pst files can't copy, while Outlook is open. :(
-
I think it is write. It is the reason, why you cannot copy .pst file, if the file is open. It because of inconsistence reason somehow.
-
And is there any method to copy these files? How about the unlocker programs, how they do it?
-
Thaks for your answers! I hope someone can help me solve this problem. I think (and hope) is there a comand line util or an assemby program, witch can do anithing with a file, witout the permisson of windows... PS.: here you can find some "magic" program , they said, can unlock locked, or in used system or other files...