Link to home
Create AccountLog in
Avatar of andyb7901
andyb7901

asked on

Vb.Net Printing File to Printer

Hey,

Does anyone know how to send a file directly to the printer, no matter what the file type is? I have a set of files currently that I double click on and they are sent directly to the printer. Or I am asked to define the file type. Can this be done in VB. Either printing direct to the printer, or performing a double click type scenario on the file through VB?
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

If Windows knows how to print the document, you can use the Process component to print it. See http://www.emoreau.com/Entries/Articles/2003/12/The-Process-component.aspx
Avatar of andyb7901
andyb7901

ASKER

I have created a little test folder to try and run this. I have tried the following;

MyProcess.StartInfo.FileName = "c:\hello\hello" - Hello delibrately has not file type.

I get en error though;

No application is associated with the specified file for this operation
The file needs an association otherwise the Windows shell (used by the process component) won't know how to print it.
I have tried to play around with your code and tried the following;

        MyProcess.StartInfo.FileName = "C:\xPrint\vpxPrint.exe"
        MyProcess.StartInfo.WorkingDirectory = "c:\hello"
        MyProcess.StartInfo.Arguments = "Hello.*"
        MyProcess.StartInfo.Verb = "Print"
        MyProcess.Start()

Can I associate all records that I want to print with the xPrint program? Is there a way to open files within certian applications?
p.s. - the above code did not work?
>>MyProcess.StartInfo.FileName = "C:\xPrint\vpxPrint.exe"

FileName is the name of the to print and not the name of the application used to print.

>>Can I associate all records that I want to print with the xPrint program?

It has to be done in Windows itself.

>>p.s. - the above code did not work?

If you take the code from the article and you try to print a file that is already associated, it will work.
No, I didnt mean your code didn't work, I meant my revised code.

Basically I need to open files that do not have file associations. I need to do this through VB. What could you suggest? All the files need to opened through my xPrint application "C:\xPrint\vpxPrint.exe".
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
At the moment if i go to my file, right click and use the "Open With" option from windows, I browse to the vpxPrint.exe. Once I have selected this it opens perfectly. With your code I get the error;

"unknown input file C:\hello"

If this does not work is there anyway to save the current file name in a variable and then rename the file it so it includes the file extension. Once I have finished with the file rename it back to its orignal name?
I have it working on the C: file now. However, when i do it on one of my real files it doesnt seem to like spaces. I have the following file to be read into the xPrint file;

"c:\hello\SUPPLIER NOTIFICATION-3177-0504200747522"

However it only seems to read NOTIFICATION-3177-0504200747522 and not the Supplier bit before that? any reason why?
have you tried:
MyProcess.StartInfo.Arguments = "c:\hello."
MyProcess.StartInfo.Arguments = "c:\hello"
I now have it working using;

Dim MyProcess As New Process
MyProcess.StartInfo.FileName = "C:\xPrint\vpxPrint.exe"
MyProcess.StartInfo.Arguments = """c:\hello\SUPPLIER NOTIFICATION-3177-0504200747522"""
MyProcess.Start()

Thanks for all your great help!
for the space, surround your file name with double quotes:

MyProcess.StartInfo.Arguments = """"  & "c:\hello" & """"