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

File in use

P: n/a
vul
I'm developing Windows Service which is going to listen MS Fax service
events and update the database when Fax Job changed its status.
I need to read OutboxLOG.txt which is used by MS Fax service.
I either would like to copy it and to work with its copy to use its data
for a database update or to copy the data from OutboxLOG.txt into another
file for further processing.
I'm using :
Do
Try
System.IO.File.Copy(strSource, strDestination, True)
Exit Do
Catch
End Try
Loop

In most cases it works, but sometimes (I have no idea what it depends on) it
doesn't. I suspect that the source file is in use and is not copied.
Could anybody suggest any other approach to copy file when it's in use, or
to copy its contents?

Thank you
Al
Feb 10 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
vul wrote:
I'm developing Windows Service which is going to listen MS Fax service
events and update the database when Fax Job changed its status.
I need to read OutboxLOG.txt which is used by MS Fax service.
I either would like to copy it and to work with its copy to use its data
for a database update or to copy the data from OutboxLOG.txt into another
file for further processing.
I'm using :
Do
Try
System.IO.File.Copy(strSource, strDestination, True)
Exit Do
Catch
End Try
Loop

In most cases it works, but sometimes (I have no idea what it depends on) it
doesn't. I suspect that the source file is in use and is not copied.
Could anybody suggest any other approach to copy file when it's in use, or
to copy its contents?

Thank you
Al


If the fax service is writing to the log at that moment you might be
screwed. You could try waiting a few seconds and trying it again. If
you copy it though you may lock the file while the fax program tries to
write to it. It would probably be better if you opened it w/ shared
permission and read it, then wrote it out.

Chris
Feb 10 '06 #2

P: n/a
Hello Vul

What version of the framework are you using?

Regards,
Simon

"vul" wrote:
I'm developing Windows Service which is going to listen MS Fax service
events and update the database when Fax Job changed its status.
I need to read OutboxLOG.txt which is used by MS Fax service.
I either would like to copy it and to work with its copy to use its data
for a database update or to copy the data from OutboxLOG.txt into another
file for further processing.
I'm using :
Do
Try
System.IO.File.Copy(strSource, strDestination, True)
Exit Do
Catch
End Try
Loop

In most cases it works, but sometimes (I have no idea what it depends on) it
doesn't. I suspect that the source file is in use and is not copied.
Could anybody suggest any other approach to copy file when it's in use, or
to copy its contents?

Thank you
Al

Feb 10 '06 #3

P: n/a
vul
How to open the file w/ shared permission and read it? Unfortunately I have
no idea

Thank you
Al

"Chris" <no@spam.com> wrote in message
news:eL**************@TK2MSFTNGP10.phx.gbl...
vul wrote:
I'm developing Windows Service which is going to listen MS Fax service
events and update the database when Fax Job changed its status.
I need to read OutboxLOG.txt which is used by MS Fax service.
I either would like to copy it and to work with its copy to use its data
for a database update or to copy the data from OutboxLOG.txt into another
file for further processing.
I'm using :
Do
Try
System.IO.File.Copy(strSource, strDestination, True)
Exit Do
Catch
End Try
Loop

In most cases it works, but sometimes (I have no idea what it depends on)
it doesn't. I suspect that the source file is in use and is not copied.
Could anybody suggest any other approach to copy file when it's in use,
or to copy its contents?

Thank you
Al


If the fax service is writing to the log at that moment you might be
screwed. You could try waiting a few seconds and trying it again. If you
copy it though you may lock the file while the fax program tries to write
to it. It would probably be better if you opened it w/ shared permission
and read it, then wrote it out.

Chris

Feb 10 '06 #4

P: n/a
vul
I have both on the server. Initially I developed Windows Service in VS 2003.
But I tried to convert it to VS 2005 and tested. I did not expect any
difference in the service behavior and there was no difference.
The same failures sometime.

Thank you
Al

"Simon Murrell" <Simon Mu*****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
Hello Vul

What version of the framework are you using?

Regards,
Simon

"vul" wrote:
I'm developing Windows Service which is going to listen MS Fax service
events and update the database when Fax Job changed its status.
I need to read OutboxLOG.txt which is used by MS Fax service.
I either would like to copy it and to work with its copy to use its data
for a database update or to copy the data from OutboxLOG.txt into another
file for further processing.
I'm using :
Do
Try
System.IO.File.Copy(strSource, strDestination, True)
Exit Do
Catch
End Try
Loop

In most cases it works, but sometimes (I have no idea what it depends on)
it
doesn't. I suspect that the source file is in use and is not copied.
Could anybody suggest any other approach to copy file when it's in use,
or
to copy its contents?

Thank you
Al

Feb 10 '06 #5

P: n/a
Hello Vul

This should work.

byte[] bytesRead = new byte[maxBytes];
long previousSeekPosition = 0;
int maxBytes = 4096;

FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite );
if (fs.Length > maxBytes)
{

this.previousSeekPosition = fs.Length - maxBytes;

}
this.previousSeekPosition = (int)fs.Seek(this.previousSeekPosition,
SeekOrigin.Begin);
int numBytes = fs.Read(bytesRead, 0, maxBytes);
fs.Close();
this.previousSeekPosition += numBytes;

StringBuilder sb = new StringBuilder();
for (int i=0; i<numBytes; i++)
{

sb.Append((char)bytesRead[i]);

}

// Your data will then be in sb.ToString();

Regards,
Simon

"vul" wrote:
I have both on the server. Initially I developed Windows Service in VS 2003.
But I tried to convert it to VS 2005 and tested. I did not expect any
difference in the service behavior and there was no difference.
The same failures sometime.

Thank you
Al

"Simon Murrell" <Simon Mu*****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.com...
Hello Vul

What version of the framework are you using?

Regards,
Simon

"vul" wrote:
I'm developing Windows Service which is going to listen MS Fax service
events and update the database when Fax Job changed its status.
I need to read OutboxLOG.txt which is used by MS Fax service.
I either would like to copy it and to work with its copy to use its data
for a database update or to copy the data from OutboxLOG.txt into another
file for further processing.
I'm using :
Do
Try
System.IO.File.Copy(strSource, strDestination, True)
Exit Do
Catch
End Try
Loop

In most cases it works, but sometimes (I have no idea what it depends on)
it
doesn't. I suspect that the source file is in use and is not copied.
Could anybody suggest any other approach to copy file when it's in use,
or
to copy its contents?

Thank you
Al


Feb 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.