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 5 1822
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: matt |
last post by:
I have compiled some code, some written by me, some compiled from
various sources online, and basically i've got a very simple flat file
photo gallery. An upload form, to upload the photos and give...
|
by: Dave Smithz |
last post by:
Hi There,
I have a PHP script that sends an email with attachment and works great when
provided the path to the file to send.
However this file needs to be on the same server as the script.
...
|
by: Joseph |
last post by:
Hi,
I'm having bit of questions on recursive pointer. I have following
code that supports upto 8K files but when i do a file like 12K i get a
segment fault. I Know it is in this line of code. ...
|
by: StGo |
last post by:
How can i read/write file's custom attributs(like subject,author...) in
C#???
Thanks :))
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: Sky Sigal |
last post by:
I have created an IHttpHandler that waits for uploads as attachments for a
webmail interface, and saves it to a directory that is defined in
config.xml.
My question is the following:
assuming...
|
by: Roy |
last post by:
Hi,
I have a problem that I have been working with for a while.
I need to be able from server side (asp.net) to detect that the file i'm
streaming down to the client is saved...
|
by: Shapper |
last post by:
Hello,
I created a script to upload a file.
To determine the file type I am using userPostedFile.ContentType.
For example, for a png image I get "image/png".
My questions are:
1. Where can...
|
by: troutbum |
last post by:
I am experiencing problems when one user has a document open through a
share pointing to the web site. I use the dsolefile to read the
contents of a particular directory and then display them in a...
|
by: thjwong |
last post by:
I'm using WinXP with Microsoft Visual C++ .NET
69462-006-3405781-18776, Microsoft Development Environment 2003 Version
7.1.3088, Microsoft .NET Framework 1.1 Version 1.1.4322 SP1
Most developers...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
| |