Click here to Skip to main content
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 22:58pm
snamyna1.2K
Edited 20-Oct-11 22: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 Kornfeld Eliyahu Peter 169
1 Zoltán Zörgő 139
2 George Jonsson 135
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2014
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