By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,750 Members | 1,456 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,750 IT Pros & Developers. It's quick & easy.

How to Copy a file

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.