Handling locked files with C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Markus Erlacher

    Handling locked files with C#

    Hi Newsgroup,

    I have a problem that is not directly C#-related, but I'd like to
    solve it in C#.

    A data acquisition station generates heaps of data, which shall be
    transferred to a server. As the connection may be rather slow, I can't
    wait until the acquisition ends - and unfortunately I don't have
    access to the data acquisition source codes.
    Is there a way to transfer this data while it is being recorded? The
    acquisition program locks the files during acquiring and writing the
    data, so opening the files and transferring the data that is already
    there, probably won't work. But there are programs out there that can
    open (for reading) locked files. How are they doing it?
    I thought, maybe Volume Shadow Services might be a way, but I could
    not find any examples proving it.

    Any ideas?

    Regards
    Markus

  • Vadym Stetsiak

    #2
    Re: Handling locked files with C#

    Hello, Markus!

    File is locked both for reading and writing?
    Did you try opening the file with, say notepad. Will it succeed?

    --
    With best regards, Vadym Stetsiak.
    Blog: http://vadmyst.blogspot.com

    You wrote on Tue, 16 Oct 2007 09:17:49 -0000:

    MEHi Newsgroup,

    MEI have a problem that is not directly C#-related, but I'd like to
    MEsolve it in C#.

    MEA data acquisition station generates heaps of data, which shall be
    MEtransferred to a server. As the connection may be rather slow, I
    MEcan't wait until the acquisition ends - and unfortunately I don't
    MEhave access to the data acquisition source codes.
    MEIs there a way to transfer this data while it is being recorded? The
    MEacquisition program locks the files during acquiring and writing the
    MEdata, so opening the files and transferring the data that is already
    MEthere, probably won't work. But there are programs out there that
    MEcan open (for reading) locked files. How are they doing it?
    MEI thought, maybe Volume Shadow Services might be a way, but I could
    MEnot find any examples proving it.

    MEAny ideas?

    MERegards
    MEMarkus


    Comment

    • Markus Erlacher

      #3
      Re: Handling locked files with C#

      Hi Vadym,

      Opening it with Notepad fails, drag-n-drop to make a copy fails also.

      regards
      Markus


      On 16 Okt., 11:52, "Vadym Stetsiak" <vadm...@gmail. comwrote:
      Hello, Markus!
      >
      File is locked both for reading and writing?
      Did you try opening the file with, say notepad. Will it succeed?
      >
      --
      With best regards, Vadym Stetsiak.
      Blog:http://vadmyst.blogspot.com

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Handling locked files with C#

        "Markus Erlacher" <markus.erlache r@gmail.comwrot e in message
        news:1192542097 .009975.299710@ e9g2000prf.goog legroups.com...
        Hi Vadym,
        >
        Opening it with Notepad fails, drag-n-drop to make a copy fails also.
        >
        Which means that the file is opened in *exclusive* mode, there is nothing
        you can do about this, no other program can open such file simultaneously.
        As you don't own the acquisition source code, VSS is not an option either.

        Willy.

        Comment

        • Markus Erlacher

          #5
          Re: Handling locked files with C#

          Hi Willy,

          thanks for the response. That's no good news for me, but probably in
          terms of security the right thing for the operating system to do. But
          thanks for the hint that even VSS is no option.
          But one thing still confuses me: how do backup softwares handle these
          files?

          Markus

          On 16 Okt., 17:59, "Willy Denoyette [MVP]"
          <willy.denoye.. .@telenet.bewro te:
          Opening it with Notepad fails, drag-n-drop to make a copy fails also.
          >
          Which means that the file is opened in *exclusive* mode, there is nothing
          you can do about this, no other program can open such file simultaneously.
          As you don't own the acquisition source code, VSS is not an option either.
          >
          Willy.

          Comment

          • Willy Denoyette [MVP]

            #6
            Re: Handling locked files with C#

            "Markus Erlacher" <markus.erlache r@gmail.comwrot e in message
            news:1192620964 .989760.48200@v 29g2000prd.goog legroups.com...
            Hi Willy,
            >
            thanks for the response. That's no good news for me, but probably in
            terms of security the right thing for the operating system to do. But
            thanks for the hint that even VSS is no option.
            But one thing still confuses me: how do backup softwares handle these
            files?
            >
            Markus
            >
            On 16 Okt., 17:59, "Willy Denoyette [MVP]"
            <willy.denoye.. .@telenet.bewro te:
            >
            Opening it with Notepad fails, drag-n-drop to make a copy fails also.
            >>
            >Which means that the file is opened in *exclusive* mode, there is nothing
            >you can do about this, no other program can open such file
            >simultaneously .
            >As you don't own the acquisition source code, VSS is not an option
            >either.
            >>
            >Willy.
            >
            >


            Basically you need to open the file using Win32 "CreateFile " API with:
            dwDesiredACcess = 0
            dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRIT E
            and dwFlagsAndAttri butes = FILE_FLAG_BACKU P_SEMANTICS set.
            Once you have the file handle, you can use it to perform backup operations
            using the Backup API's like Kernel32 API "BackupRead ".
            Nothing of this all is wrapped by the Framework, you need to PInvoke. Also,
            you need to run with the "SeBackupPrivil ege "enabled for your process, (IMO)
            something you don't want your user processes to run with.


            Willy.

            Comment

            Working...