Home All Groups Group Topic Archive Search About
Author
10 Feb 2006 3:46 PM
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

Author
10 Feb 2006 4:46 PM
Chris
vul wrote:
Show quote
> 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
Author
10 Feb 2006 10:26 PM
vul
How to open the file w/ shared permission and read it? Unfortunately I have
no idea

Thank you
Al

Show quote
"Chris" <no@spam.com> wrote in message
news:eLK8AGmLGHA.3936@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
Author
10 Feb 2006 7:58 PM
Simon Murrell
Hello Vul

What version of the framework are you using?

Regards,
Simon

Show quote
"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
>
>
>
Author
10 Feb 2006 10:29 PM
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

Show quote
"Simon Murrell" <Simon Murr***@discussions.microsoft.com> wrote in message
news:FCE9D345-A3F0-46BE-996F-7140A590B668@microsoft.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
>>
>>
>>
Author
11 Feb 2006 7:44 AM
Simon Murrell
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

Show quote
"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 Murr***@discussions.microsoft.com> wrote in message
> news:FCE9D345-A3F0-46BE-996F-7140A590B668@microsoft.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
> >>
> >>
> >>
>
>
>

AddThis Social Bookmark Button