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. C#
  4. Copy or read locked/in use files

Copy or read locked/in use files

Scheduled Pinned Locked Moved C#
help
7 Posts 2 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.
  • N Offline
    N Offline
    nemopeti
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • N nemopeti

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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".

      N 1 Reply Last reply
      0
      • L Lost User

        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".

        N Offline
        N Offline
        nemopeti
        wrote on last edited by
        #3

        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. :(

        L 1 Reply Last reply
        0
        • N nemopeti

          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. :(

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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.

          N 1 Reply Last reply
          0
          • L Lost User

            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.

            N Offline
            N Offline
            nemopeti
            wrote on last edited by
            #5

            And is there any method to copy these files? How about the unlocker programs, how they do it?

            L 1 Reply Last reply
            0
            • N nemopeti

              And is there any method to copy these files? How about the unlocker programs, how they do it?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I don't think so... I've never heard about unlocker program.

              N 1 Reply Last reply
              0
              • L Lost User

                I don't think so... I've never heard about unlocker program.

                N Offline
                N Offline
                nemopeti
                wrote on last edited by
                #7

                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...

                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