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?
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?
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
ASKER
I have created a little test folder to try and run this. I have tried the following;
MyProcess.StartInfo.FileNa me = "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
MyProcess.StartInfo.FileNa
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.
ASKER
I have tried to play around with your code and tried the following;
MyProcess.StartInfo.FileNa me = "C:\xPrint\vpxPrint.exe"
MyProcess.StartInfo.Workin gDirectory = "c:\hello"
MyProcess.StartInfo.Argume nts = "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?
MyProcess.StartInfo.FileNa
MyProcess.StartInfo.Workin
MyProcess.StartInfo.Argume
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?
ASKER
p.s. - the above code did not work?
>>MyProcess.StartInfo.File Name = "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.
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.
ASKER
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".
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
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?
"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?
ASKER
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-05042007 47522"
However it only seems to read NOTIFICATION-3177-05042007 47522 and not the Supplier bit before that? any reason why?
"c:\hello\SUPPLIER NOTIFICATION-3177-05042007
However it only seems to read NOTIFICATION-3177-05042007
have you tried:
MyProcess.StartInfo.Argume nts = "c:\hello."
MyProcess.StartInfo.Argume nts = "c:\hello"
MyProcess.StartInfo.Argume
MyProcess.StartInfo.Argume
ASKER
I now have it working using;
Dim MyProcess As New Process
MyProcess.StartInfo.FileNa me = "C:\xPrint\vpxPrint.exe"
MyProcess.StartInfo.Argume nts = """c:\hello\SUPPLIER NOTIFICATION-3177-05042007 47522"""
MyProcess.Start()
Thanks for all your great help!
Dim MyProcess As New Process
MyProcess.StartInfo.FileNa
MyProcess.StartInfo.Argume
MyProcess.Start()
Thanks for all your great help!
for the space, surround your file name with double quotes:
MyProcess.StartInfo.Argume nts = """" & "c:\hello" & """"
MyProcess.StartInfo.Argume