471,320 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,320 software developers and data experts.

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

Oct 16 '07 #1
5 6798
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
Oct 16 '07 #2
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
Oct 16 '07 #3
"Markus Erlacher" <ma*************@gmail.comwrote in message
news:11**********************@e9g2000prf.googlegro ups.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.

Oct 16 '07 #4
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.bewrote:
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.

Oct 17 '07 #5
"Markus Erlacher" <ma*************@gmail.comwrote in message
news:11*********************@v29g2000prd.googlegro ups.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.bewrote:
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_WRITE
and dwFlagsAndAttributes = FILE_FLAG_BACKUP_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 "SeBackupPrivilege "enabled for your process, (IMO)
something you don't want your user processes to run with.
Willy.

Oct 17 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Neil | last post: by
10 posts views Thread by Martin Ho | last post: by
5 posts views Thread by cmay | last post: by
3 posts views Thread by Kirt | last post: by
6 posts views Thread by elake | last post: by
11 posts views Thread by Jim in Arizona | last post: by
5 posts views Thread by breal | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.