Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Handling locked files with C#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Markus Erlacher - 16 Oct 2007 10:17 GMT
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 - 16 Oct 2007 10:52 GMT
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:

ME> Hi Newsgroup,

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

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

ME> Any ideas?

ME> Regards
ME> Markus
Markus Erlacher - 16 Oct 2007 14:41 GMT
Hi Vadym,

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

regards
Markus

> Hello, Markus!
>
[quoted text clipped - 4 lines]
> With best regards, Vadym Stetsiak.
> Blog:http://vadmyst.blogspot.com
Willy Denoyette [MVP] - 16 Oct 2007 16:59 GMT
> 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.
Markus Erlacher - 17 Oct 2007 12:36 GMT
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.be> wrote:

> > Opening it with Notepad fails, drag-n-drop to make a copy fails also.
>
[quoted text clipped - 3 lines]
>
> Willy.
Willy Denoyette [MVP] - 17 Oct 2007 16:20 GMT
> Hi Willy,
>
[quoted text clipped - 18 lines]
>>
>> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.