473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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

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
1 1631
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit...
20
by: Brad Eck | last post by:
"The only operators that cannot be overloaded are :: (scope resolution), . (member selection), and .* (member selection through pointer to function). Quoting from Stroustrup's 3rd edition of _The...
2
by: Trevor Davies | last post by:
I have a database which I have loaded onto our as/400 v4r5. All the tables and data have loaded successfully. I am using DB2 connect to access. I now want to delete the data in a table which is...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
3
by: happy | last post by:
/* Book name : The prodessional programmers guide to C File name : E:\programs\tc\iti01\ch09\main\01setupm.c Program discription: file setuping -up -Version 01-ver01-W Logic ...
0
by: newms | last post by:
The following thread is related to a file access problem that seems to be a C# language problem. I have temporarily resolved it with vb.net as described below and thought it might be helpful to...
6
by: Greg Collins [MVP] | last post by:
For background, please refer to my original thread: http://groups.google.com/groups?selm=efe5w7tYEHA.3112%40tk2msftngp13.phx.gbl I've thought of a potential way around the issue, but I'm new to...
5
by: Sam777 | last post by:
I was under the impression that creating the app_offline.htm file at the root of the webapp would cause all handles to be closed so that the app could be removed. Unfortunately, this isn't the...
4
by: RedJoy | last post by:
I am switching from VS2003 .NET to VS2005 and I receive the following errorwhen compiling my project: error C3821: 'File': managed type or function cannot be used in an unmanaged function...
0
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
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.