allow users to select printer when printing multiple files in vb.net using system.process

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am trying to allow users to select a printer to print multiple files (word documents, pdf files, journal files, etc.) to from a sql 2008r2 database. The following code works fine but uses the default printer on each workstation:
<p style="line-height:normal; margin-bottom:0pt <span style="color:blue; font-family:Consolas; font-size:9.5pt Dim<span style="font-family:Consolas; font-size:9.5pt RowCount, i
<span style="color:blue As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt RowCount =
<span style="color:blue Me.VwDataGridView.Rows.GetRowCount(<span style="color:#2b91af DataGridViewElementStates.Displayed)<span>

<p style="margin:0in 0in 0pt 0.5in; line-height:normal <span style="font-family:Consolas; font-size:9.5pt F<span style="color:blue or i = 0
<span style="color:blue To RowCount - 1 <span style="color:green loop through all rows in DataGridView
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim Row <span style="color:blue As
<span style="color:#2b91af DataGridViewRow
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Row = <span style="color:blue Me.VwDataGridView.Rows(i)
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim FileNamePath <span style="color:blue
As <span style="color:blue String <span style="color:green Get file name path
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
FileNamePath = Row.Cells(7).Value <span style="color:green get path to file
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> <span style="color:blue Dim Process
<span style="color:blue As <span style="color:blue New <span style="color:#2b91af
Process
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.UseShellExecute = <span style="color:blue True
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.FileName = FileNamePath <span style="color:green give filename to process
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> Process.StartInfo.Verb = <span style="color:#a31515
"Print"
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.CreateNoWindow = <span style="color:blue True
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.WindowStyle = <span style="color:#2b91af ProcessWindowStyle.Hidden
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.Start()
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.CloseMainWindow()
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> Process.Close()
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process = <span style="color:blue Nothing
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Next i
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt MsgBox(<span style="color:#a31515 "That should do it! All done.")
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt I would like users to be able to use a PrintDialog to select the printer and #of copies. This code does not work and simply sends everything to the same default printer:
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="background:yellow; color:blue; font-family:Consolas; font-size:9.5pt If<span style="background:yellow; font-family:Consolas; font-size:9.5pt PrintDialog1.ShowDialog = Windows.Forms.<span style="color:#2b91af DialogResult.OK
<span style="color:blue Then
<p style="line-height:normal; margin-bottom:0pt <span style="background:yellow; font-family:Consolas; font-size:9.5pt <span>
PrintDialog1.Document = <span style="color:blue Nothing
<p style="line-height:normal; margin-bottom:0pt <span style="background:yellow; font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim PrinterArguments <span style="color:blue
As <span style="color:#2b91af DialogResult = Windows.Forms.<span style="color:#2b91af DialogResult.OK
<p style="line-height:normal; margin-bottom:0pt <span style="color:blue; font-family:Consolas; font-size:9.5pt Dim<span style="font-family:Consolas; font-size:9.5pt RowCount, i
<span style="color:blue As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt RowCount =
<span style="color:blue Me.VwDataGridView.Rows.GetRowCount(<span style="color:#2b91af DataGridViewElementStates.Displayed)<span>

<p style="margin:0in 0in 0pt 0.5in; line-height:normal <span style="font-family:Consolas; font-size:9.5pt F<span style="color:blue or i = 0
<span style="color:blue To RowCount - 1 <span style="color:green loop through all rows in DataGridView
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim Row <span style="color:blue As
<span style="color:#2b91af DataGridViewRow
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Row = <span style="color:blue Me.VwDataGridView.Rows(i)
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim FileNamePath <span style="color:blue
As <span style="color:blue String <span style="color:green Get file name path
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
FileNamePath = Row.Cells(7).Value <span style="color:green get path to file
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> <span style="color:blue Dim Process
<span style="color:blue As <span style="color:blue New <span style="color:#2b91af
Process
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.UseShellExecute = <span style="color:blue True
<p style="margin:0in 0in 0pt 1in; line-height:normal <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="background:yellow Process.StartInfo.Arguments = PrinterArguments.ToString
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.FileName = FileNamePath <span style="color:green give filename to process
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> Process.StartInfo.Verb = <span style="color:#a31515
"Print"
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.CreateNoWindow = <span style="color:blue True
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.StartInfo.WindowStyle = <span style="color:#2b91af ProcessWindowStyle.Hidden
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.Start()
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process.CloseMainWindow()
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> Process.Close()
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
Process = <span style="color:blue Nothing
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Next i
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
MsgBox(<span style="color:#a31515 "That should do it! All done.")
<p style="line-height:normal; margin-bottom:0pt <span style="color:#0070c0; font-family:Consolas; font-size:9.5pt End If
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt The printer arguments are not being passed on to the Process. Not sure where to go from here.
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt Thank you in advance from a true rookie!
<span style="font-size:small <span style="font-size:small

View the full article
 
Back
Top