Cannot delete file after it is processed in a function with FileMo

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a application that opens a file, sends it a printer and then (tries)
to delete it. It is based on the example from Microsoft:
http://support.microsoft.com/?kbid=322091

In my application I have the following code but I always get a file in use
exception when I try to delete the file:

Sub Main(ByVal CmdArgs() As String)
If CmdArgs.Length >= 2 Then
Dim docName = CmdArgs(0)
Dim prName = CmdArgs(1)
Try
RawPrinterHelper.SendFileToPrinter(prName, docName)
Catch ex As Exception
EventLog.WriteEntry("PCLPrinter", "Failed to print PCL file
" & docName & " to printer " & prName & ". More info: " & ex.Message)
End Try
If CmdArgs.Length = 3 Then
If CmdArgs(2) = "/delete" Then
File.Delete(docName)
End If
End If
End If

Is this caused because in the function SendFileToPrinter contains code that
opens a file but does not close it? And how can I close a file?
 
Simple fs.close did the track.

Thanks to all who were interested in the topic.

P.s. If any Microsoft people read this: Maybe update the support article?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top