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

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

P: n/a
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?
Feb 10 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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?

"Philip Wagenaar" wrote:
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?

Feb 10 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.