473,480 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Copy a file while it is open

I am trying to write a small utility program that backs up a list of
files/folders

I need to back up all files including those that are opened, is ther a way
of doing that? (it seems that backup programs are doing just that)

Thank you,
Samuel
Mar 15 '07 #1
6 2113
"Samuel" <sa************@ntlworld.comschrieb:
>I am trying to write a small utility program that backs up a list of
files/folders

I need to back up all files including those that are opened, is ther a way
of doing that? (it seems that backup programs are doing just that)

Basically you can do that using the classes in the 'System.IO' namespace,
except for files that are opened exclusively for reading by other processes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 16 '07 #2
Thank you for your reply,

And what can be done in the case of a file being exclusively opened by
another process?

Do backup program copy these files as well (I think they do)

Samuel

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
"Samuel" <sa************@ntlworld.comschrieb:
>>I am trying to write a small utility program that backs up a list of
files/folders

I need to back up all files including those that are opened, is ther a
way of doing that? (it seems that backup programs are doing just that)


Basically you can do that using the classes in the 'System.IO' namespace,
except for files that are opened exclusively for reading by other
processes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 16 '07 #3
Backup programs use various methods to attempt to backup files that are locked. In the
case of databases (i.e. Exchange) an agent can be used to connect to the database and read
the info that way. In the case of other types of files, you could try to create shadow
copies of the files you think will be in use when doing backups. Never done it, but it
sounds like an interesting thing to try. Sometimes files that are in use are not able to
be backed up.

Samuel wrote:
Thank you for your reply,

And what can be done in the case of a file being exclusively opened by
another process?

Do backup program copy these files as well (I think they do)

Samuel

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...

Mar 16 '07 #4
On Fri, 16 Mar 2007 17:30:41 -0000, Samuel wrote:
Thank you for your reply,

And what can be done in the case of a file being exclusively opened by
another process?

Do backup program copy these files as well (I think they do)

Samuel

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>"Samuel" <sa************@ntlworld.comschrieb:
>>>I am trying to write a small utility program that backs up a list of
files/folders

I need to back up all files including those that are opened, is ther a
way of doing that? (it seems that backup programs are doing just that)


Basically you can do that using the classes in the 'System.IO' namespace,
except for files that are opened exclusively for reading by other
processes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Not sure if this is possble --- and if it is, i'm not sure it's entirely
wise. Backing up an open file has a number of considerations. It is up to
the discretion of the application how frequently to write the file to disk.
Thus you might back up an incomplete file that might appear later to be
corrupt
--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 16 '07 #5
Look at the Shadow Copy API. This API set was designed for this
idea. You will have one issue, kernel exclusive control for read/
write access will always block user space requests for read. If a
process has NOT allowed a user process to read shared, while another
process has exclusive read/write will be an issue. How Microsoft gets
past this, is some what inconsistent. NTBackup for example even has
trouble reading SOME things.

Mar 17 '07 #6
Thanks for your reply

1. How can I find out whether a file is opened
2. If a file is open how can know whether the current state of the file is
complete? if that's possible at all

Regards,
Samuel

"Rad [Visual C# MVP]" <no****@nospam.comwrote in message
news:2v**************@thinkersroom.com...
On Fri, 16 Mar 2007 17:30:41 -0000, Samuel wrote:
>Thank you for your reply,

And what can be done in the case of a file being exclusively opened by
another process?

Do backup program copy these files as well (I think they do)

Samuel

"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>"Samuel" <sa************@ntlworld.comschrieb:
I am trying to write a small utility program that backs up a list of
files/folders

I need to back up all files including those that are opened, is ther a
way of doing that? (it seems that backup programs are doing just that)
Basically you can do that using the classes in the 'System.IO'
namespace,
except for files that are opened exclusively for reading by other
processes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Not sure if this is possble --- and if it is, i'm not sure it's entirely
wise. Backing up an open file has a number of considerations. It is up to
the discretion of the application how frequently to write the file to
disk.
Thus you might back up an incomplete file that might appear later to be
corrupt
--
Bits.Bytes
http://bytes.thinkersroom.com

Mar 18 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2072
by: SeanR | last post by:
I have a function to copare two files. It will first copy the original file form a different server to a local temp path and then compare that version to a version that has been restored form tape....
2
2048
by: juli jul | last post by:
Hello, I am trying to overwrite a file in this way: File.Copy(this.file_name,this.file_name,true); The problem is that I get this error: An unhandled exception of type 'System.IO.IOException'...
8
2902
by: luis molina Micasoft | last post by:
it seems that when i do file.copy the svchost.exe is hanged, i mean if i make 40 threads of file.copy , 40 copys of files at same time the system is going down and stop responding, this is when i'm...
7
11593
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
4
7006
by: Jon Asher | last post by:
Hi, I'm trying to do a simple import of a comma delimited text file with COPY but it's returning an error. The file has been granted all permissions in Linux, so it's not clear to me what the...
11
18136
by: MarkusR | last post by:
Good day, I need to safely copy files from one directory to another. I need to make sure that I do not lock the file making it unreadable by others. I am not sure if this is the default...
0
2582
by: Paul Brady | last post by:
I volunteer at a youth ministry agency and help them with their student database. They have two computers, both running Windows XP. Both have Office 2002 installed without Access, except that...
25
2853
by: Andy_Khosravi | last post by:
I just recently changed my database that I'm running from a monolithic DB to a split FE/BE. The front end resides on the client machine and the BE resides on a network drive. I'm experimenting with...
13
2580
by: jim | last post by:
Is there a way (using VB.Net or C#) to copy open or locked files? Thanks! jim
0
7033
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4468
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1291
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
557
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.