Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Copying Locked File

Copying Locked File

Scheduled Pinned Locked Moved Visual Basic
csharpcomtutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sameers Javed
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • S Sameers Javed

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        S Offline
        S Offline
        Sameers Javed
        wrote on last edited by
        #3

        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

        D C 2 Replies Last reply
        0
        • S Sameers Javed

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • S Sameers Javed

            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

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups