Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Filesystemwatcher synchronous
Message
From
31/08/2009 23:33:38
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Filesystemwatcher synchronous
Environment versions
Environment:
VB 9.0
OS:
Vista
Miscellaneous
Thread ID:
01422062
Message ID:
01422062
Views:
119
I am creating a PDF programmatically. The ActiveX component basically acts as a printer driver and I can't figure out how to know when it is done so I know the file exists for certain so I can read it into a byte array to store.

I am trying now to do this with system.io.filesystemwatcher but I can't seem to get the syntax right

Here is what I am playing around with :
  Public Function CreatePDFBytes(ByVal rtfstr As String) As Byte()

        ' PDFCreator has been created by the calling program

        ' create temporary directory and temporary filename

        Dim temppath As String = "c:\pdftemp"

        Dim fileBase As String = Path.GetFileNameWithoutExtension(Path.GetRandomFileName)
        Dim tempfile As String = fileBase & ".rtf"
        Dim tempfull As String = Path.Combine(temppath, tempfile)

        Dim temppdf As String = fileBase & ".pdf"
        Dim pdffull As String = Path.Combine(temppath, temppdf)


        ''-- Write out RTF
        File.WriteAllText(tempfull, rtfstr)

        '-- Convert to PDF and write to disk

        Dim pdfo As PDFCreator.clsPDFCreatorOptions

        pdfo = Me.Creator.cOptions

        '-- Setup options
        With pdfo
            .UseAutosave = 1
            .AutosaveFilename = temppdf
            ' .StartStandardProgram = 1
            .AutosaveDirectory = temppath

        End With

        Me.Creator.cOptions = pdfo

        Dim pdfbyte As Byte() = Nothing

        Using watcher As New FileSystemWatcher()

            watcher.Path = temppath
            watcher.Filter = "*.pdf"

            watcher.EnableRaisingEvents = True

' here is where i am confused 
' 
            Dim results As WaitForChangedResult

'this is the line that actually creates the pdf - it works, but my problem has been 
' if I don't wait until it is definitely created I'll get an error when I try to read it into
' the array.  If I step through and don't run the line to read the pdf to the byte array 
' until I see the file is definitely there, all is well
' as many as twenty files may be processed in a loop
' can't wrap my head around the sequence of the next two lines
' if I create first, I'm not waiting 
' if I wait first I time out before I'm creating

            Me.Creator.cPrintFile(tempfull)

            results = watcher.WaitForChanged(WatcherChangeTypes.Created, 20000)

            If results.TimedOut Then
' handle failure to create
            Else
' read the file into pdfbyte
           end if

        End Using

        Return pdfbyte

    End Function
Thoughts ?

TIA


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Next
Reply
Map
View

Click here to load this message in the networking platform