473,395 Members | 1,762 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to Copy a file

Tom
I am having trouble when I read a file and another process
is trying to update it.

So I need a rountine to copy a file in asp.net.

Can anyone assist?

Thanks

Tom

Nov 15 '05 #1
6 3258
using System.IO;

....

public static bool copyFile
(string source, string destination, bool overwrite) {
File.Copy(source, destination, overwrite);
}

"Tom" <da*****@fhlbcin.com> wrote in message
news:03****************************@phx.gbl...
I am having trouble when I read a file and another process
is trying to update it.

So I need a rountine to copy a file in asp.net.

Can anyone assist?

Thanks

Tom

Nov 15 '05 #2
Hi,

Try this.

C# code example ;
----------------
The use the System.IO namespace

File.Copy(@"C:\MyFile.Txt", @"C:\MyOtherDir\MyFile.Txt");
//To copy to a different file name is also possible
File.Copy(@"C:\MyFile.Txt",
@"C:\MyOtherDir\MyNewFileName.Txt");
-----Original Message-----
I am having trouble when I read a file and another processis trying to update it.

So I need a rountine to copy a file in asp.net.

Can anyone assist?

Thanks

Tom

.

Nov 15 '05 #3
Hi Tom,

If you are able to copy the file manually in Windows Explorer, ie
the Windows Shell can do it, try invoking Shell from your program.

Process.Start() is one area you might look at.

Regards,
Fergus
Nov 15 '05 #4

Tom wrote:
|| Chris:
||
|| Thanks for that but I'm still having trouble.
||
|| See I wish to access a file (CrawlerStatus.txt) to see if
|| the search is done. CrawlerStatus.txt is a text file that
|| gets updated by a third party software.
||
|| Anyway, when I used StreamReader object, to get the
|| contents WHILE the process was updating the file, I got an
|| error.
||
|| So I thought copying it and then use StreamReader to query
|| the copied file contents would do the trick. But I'm
|| getting the same error.
||
|| So do you know of a way to access a file while its being
|| updated so as to not harm it?
||
|| TOm

You can't copy the file simply because the thrird party didn't open the file with shared read access.

Willy.
Nov 15 '05 #5
I did a little more research, and I believe I found what you need.

IF YOUR application is the one that's writing to the file, you should use
share access. That is, when you open the file to write to it, you can
specify several different file modes, and one of them is sharing. Use
System.IO.FileShare.Read to be enable it to share with other processes that
wish to read from the file while it's being updated.

on the other hand, if you don't have the ability to change the code of the
program that's writing to the file, then you will just have to continue to
try to open it until that process is done with the file. If the process
that's writing the file never releases control of the file, then it's not
possible (as far as I know).

Chris LaJoie
"Tom" <da*****@fhlbcin.com> wrote in message
news:04****************************@phx.gbl...
Chris:

Thanks for that but I'm still having trouble.

See I wish to access a file (CrawlerStatus.txt) to see if
the search is done. CrawlerStatus.txt is a text file that
gets updated by a third party software.

Anyway, when I used StreamReader object, to get the
contents WHILE the process was updating the file, I got an
error.

So I thought copying it and then use StreamReader to query
the copied file contents would do the trick. But I'm
getting the same error.

So do you know of a way to access a file while its being
updated so as to not harm it?

TOm
-----Original Message-----
using System.IO;

....

public static bool copyFile
(string source, string destination, bool overwrite)

{
File.Copy(source, destination, overwrite);
}

"Tom" <da*****@fhlbcin.com> wrote in message
news:03****************************@phx.gbl...
I am having trouble when I read a file and another process is trying to update it.

So I need a rountine to copy a file in asp.net.

Can anyone assist?

Thanks

Tom

.

Nov 15 '05 #6
Hi!

Apparently the third party software doesnt allow the file to be read when
being updated. There's nothing that you can do about it.

So, the best bet is to poll the file status and when its free, you should
proceed to read it.

--

Regards,
Gaurav Khanna
----------------------------------------------------------------------------
----------------
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
"Tom" <da*****@fhlbcin.com> wrote in message
news:04****************************@phx.gbl...
Chris:

Thanks for that but I'm still having trouble.

See I wish to access a file (CrawlerStatus.txt) to see if
the search is done. CrawlerStatus.txt is a text file that
gets updated by a third party software.

Anyway, when I used StreamReader object, to get the
contents WHILE the process was updating the file, I got an
error.

So I thought copying it and then use StreamReader to query
the copied file contents would do the trick. But I'm
getting the same error.

So do you know of a way to access a file while its being
updated so as to not harm it?

TOm
-----Original Message-----
using System.IO;

....

public static bool copyFile
(string source, string destination, bool overwrite)

{
File.Copy(source, destination, overwrite);
}

"Tom" <da*****@fhlbcin.com> wrote in message
news:03****************************@phx.gbl...
I am having trouble when I read a file and another process is trying to update it.

So I need a rountine to copy a file in asp.net.

Can anyone assist?

Thanks

Tom

.

Nov 15 '05 #7

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

Similar topics

19
by: Claudio Grondi | last post by:
I would like to save time copying the same file (>6 GByte) to various different target storage media connected to the system via USB. Is there a (Python or other) tool able to help me to do...
0
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....
0
by: Joshua Ginsberg | last post by:
Howdy -- I have a class that has an attribute that is a dictionary that contains an object that has a kword argument that is a lambda. Confused yet? Simplified example: import copy class...
5
by: DraguVaso | last post by:
Hi, I need a SECURE way to copy parts of a file. I'm having files which contains a whole bunch of records. In one 'fysical' file I'm having one or more logical files. What I need to do is to...
8
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
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
by: Emin | last post by:
Dear experts, I got some unexpected behavior in getattr and copy.deepcopy (see transcript below). I'm not sure if this is actually a bug in copy.deepcopy or if I'm doing something too magical...
1
by: ajc308 | last post by:
I'm attempting to sort the <file>s within each <directory> in my XML according to their file extension, then write out the resulting sorted data back to XML format. I had it working before, and when...
3
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.