Copying Locked File
-
Hi, Is there any tip regarding copying locked file? For example the outlook.pst file which is locked and user can not copy that if the outlook is open. Any tip/piece of code will be appreciated. Or is there any third party activeX/ .NET DLL for this purpose? Thanks, Sameers http://www.developersinn.net
-
Hi, Is there any tip regarding copying locked file? For example the outlook.pst file which is locked and user can not copy that if the outlook is open. Any tip/piece of code will be appreciated. Or is there any third party activeX/ .NET DLL for this purpose? Thanks, Sameers http://www.developersinn.net
Nope. Locked is locked for a reason. There's no getting around it. Even reading the disk sectors the file is stored in won't help. The best you can do is to try:
Dim fs As New FileStream("filename", FileMode.Open, _
FileAccess.Read, FileShare.Read)and copy the file yourself. If this doesn't work, you're sunk. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Nope. Locked is locked for a reason. There's no getting around it. Even reading the disk sectors the file is stored in won't help. The best you can do is to try:
Dim fs As New FileStream("filename", FileMode.Open, _
FileAccess.Read, FileShare.Read)and copy the file yourself. If this doesn't work, you're sunk. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Well, think if I am writing something like backup service. I must then read the file(s) which are even locked or in-use. as per the code snippet, it will allow you to open file, but you will not be able to read even a single byte as you will end with message something like this "Can not read. Part of the file is locked by some other process". Still need to think.... thanks, Sameers http://www.developersinn.net Need to get reminded for your outlook emails? try www.outlookpa.com
-
Well, think if I am writing something like backup service. I must then read the file(s) which are even locked or in-use. as per the code snippet, it will allow you to open file, but you will not be able to read even a single byte as you will end with message something like this "Can not read. Part of the file is locked by some other process". Still need to think.... thanks, Sameers http://www.developersinn.net Need to get reminded for your outlook emails? try www.outlookpa.com
That's not going to happen using standard file I/O methods. You'll have to write a device driver to get access to the disk below where the file system starts. Search for a book called "NTFS Internals" for more information. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Well, think if I am writing something like backup service. I must then read the file(s) which are even locked or in-use. as per the code snippet, it will allow you to open file, but you will not be able to read even a single byte as you will end with message something like this "Can not read. Part of the file is locked by some other process". Still need to think.... thanks, Sameers http://www.developersinn.net Need to get reminded for your outlook emails? try www.outlookpa.com
Sameers (theAngrycodeR ) wrote:
think if I am writing something like backup service
Are you writing a backup service? The reason applications can lock files, preventing other applications from reading the file, is that the file is most likely going to be in a state of flux. Any application that reads the file will not be able to determine if the file contents are safe or not because they are subject to change. You might read one part which is fine, then the next part which has changed and no longer makes sense when placed next to the first part.
Sameers (theAngrycodeR ) wrote:
I must then read the file(s) which are even locked or in-use
I would suggest that makes for a bit of a dodgy backup. For example: SQL Server provides its own backup engine which creates a new file that is in a consistent state because you cannot safely perform a file backup directly from the filesystem. ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell