Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hye..

I am using this code to enable print function on a button.

VB
Protected Sub PrintBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrintBtn.Click
       Dim psiPrint As New System.Diagnostics.ProcessStartInfo()
       psiPrint.Verb = "print"
       psiPrint.WindowStyle = ProcessWindowStyle.Hidden
       psiPrint.FileName = "Form.pdf"
       psiPrint.UseShellExecute = True
       System.Diagnostics.Process.Start(psiPrint)
   End Sub


Error occurred stating that
The system cannot find the file specified

at line
System.Diagnostics.Process.Start(psiPrint)


How can I solve this?
My Form.pdf is located in a folder Form
Posted
Updated 20-Oct-11 21:59pm
v2

Specify the relative or absolute path of the file to be processed.
For example:
VB
psiPrint.FileName = "C:\\Form\\Form.pdf"
 
Share this answer
 
Comments
snamyna 21-Oct-11 4:08am    
My Form.pdf is located in my system folder (e-Stars new) and that folder is located at the desktop. I have tried this code but the same error occurs.
psiPrint.FileName = "~\e-Stars new\Form\Form.pdf"
snamyna 21-Oct-11 4:11am    
If using the code that you have given, is it possible for other person who run this system in other pc to print the Form.pdf?
I have solved it. Thanks for your time anyway.

VB
Protected Sub PrintBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PrintBtn.Click
       Dim psiPrint As New System.Diagnostics.ProcessStartInfo()
       psiPrint.Verb = "print"
       psiPrint.WindowStyle = ProcessWindowStyle.Hidden
       psiPrint.FileName = Server.MapPath("~\Form\Form.pdf")
       psiPrint.UseShellExecute = True
       System.Diagnostics.Process.Start(psiPrint)
   End Sub
 
Share this answer
 
Comments
red_dog 7-Jun-13 2:32am    
Hi snamyna.
I did like you did, but i have a problem in line System.Diagnostics.Process.Start(psiPrint)
(No application is associated with the specified file for this operation). Did I miss something, please help me. Thank you.
snamyna 7-Jun-13 3:12am    
While debugging, try check at psiPrint.FileName whether your filename is exactly located as you state in Server.MapPath("//your file path here//")
red_dog 13-Jun-13 22:15pm    
Hi snamyna.
I found the problem in line psiPrint.Verb = "print".
Maybe it dose not work in window 7 64 bit. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900