0

In my vb.net program I allow users to print arbitrary documents using Process.start and loading the processstartinfo with the proper parameters:

  Dim p As New System.Diagnostics.ProcessStartInfo
                p.Verb = "Print"
                p.WindowStyle = ProcessWindowStyle.Hidden
                p.FileName = report_to_run
                p.UseShellExecute = True
                System.Diagnostics.Process.Start(p)

This works well for filenames that are directly referenced (i.e. "C:\myfile.doc"). However, one customer wants to print docs that reside on their website. The filename would be like this "http:\\www.mysite.com\Mydoc.doc". When I execute the process.start with this filename I get a "bad parameter" message.
My assumption is that it's having a problem because the directly referenced filenames ("myfile.doc") kicks of MSWord directly and MSWord interprets the "print" parameter, where the filename "http:\www.mysite.com\myfile.doc" first goes through the web browser (IE) and the browser then kicks off MSWord. My question is how can I get a web document to print programmatically?

Ron V
  • 11
  • 4
  • Why would you use `Process.Start` to print a document? .net has a perfectly good PrintDocument component. – Jeroen Jan 18 '16 at 21:37
  • When doing process.start() to http, your default browser is started, and your parameters are sent to it. Not sure your default browser will always (or ever) support the "Print" verb but to ensure it works like you want, you should download the document first to your temp folder and then process.start() it. – Steve Jan 18 '16 at 23:48
  • Also, Process.Start will likely break your app if users "accidentally" open a document for which no default application exists... – Jeroen Jan 19 '16 at 00:55
  • Thanks for the feedback. I'll investigate PrintDocument, and also will investigate downloading the document first. FYI the reason we went with process.start originally was because we also have a "browse" type function and process.start opened the document in its native application. – Ron V Jan 19 '16 at 20:17

0 Answers0