Click here to Skip to main content
11,578,524 members (58,404 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB ASP.NET PDF
Hye..

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

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 20-Oct-11 21:58pm
snamyna1.4K
Edited 20-Oct-11 21:59pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Specify the relative or absolute path of the file to be processed.
For example:
psiPrint.FileName = "C:\\Form\\Form.pdf"
  Permalink  
Comments
snamyna at 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 at 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?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I have solved it. Thanks for your time anyway.

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
  Permalink  
Comments
red_dog at 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 at 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 at 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)

  Print Answers RSS
0 Peter Leow 135
1 OriginalGriff 113
2 Richard MacCutchan 85
3 Frankie-C 75
4 Afzaal Ahmad Zeeshan 75
0 OriginalGriff 904
1 Sergey Alexandrovich Kryukov 715
2 Abhinav S 573
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 393


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100