2

Given:

  • We have a list-based application that allows you do link a File to an entry.

  • 0...1 Relationship from entry to file. (finding out if there is a file or not is my part, dont worry about that)

  • Since we know who is going to use the application we can tell that most, but not all files, will be Microsoft Office (Word/Excel) Files.

Need:

  • A way to print these Files (if windows knows how to do so)

My Thoughts:

Since we don't know the type (.pdf, .exe) of the file we will have to ask Windows if its printable and let Windows do the job for us.

My related code:

There is no. I am not experienced working directly from application to Windows which is the reason why i don't know how to start it. I'd appreciate if you could link me some usefull guides about that, if you know some.

Related Questions/Links:

Community
  • 1
  • 1
Luke
  • 751
  • 2
  • 7
  • 32
  • 1
    Following your related question, here is how to use ShellExecute in .Net : [ShellExecute equivalent in .NET](http://stackoverflow.com/questions/258416/shellexecute-equivalent-in-net). You need to set ProccessStartInfo and Verb properly... – Martin Verjans May 03 '16 at 08:22

1 Answers1

2

Provided windows is set-up to print a file the following code should do exactly the same as right clicking on a file and selecting print:

    Dim process As System.Diagnostics.Process = New Process()
    Dim startInfo As New ProcessStartInfo()
    startInfo.FileName = filename 
    startInfo.Verb = "Print" 'prints to default printer
    startInfo.UseShellExecute = True
    startInfo.WindowStyle = ProcessWindowStyle.Hidden
    startInfo.CreateNoWindow = True
    process.StartInfo = startInfo
    process.Start()
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • That one looks promissing. What if i didn't want to use the default printer and use a user-selected printer instead ? – Luke May 03 '16 at 10:27
  • This code only prints to the default printer and with the printer's default settings. As I painfully found out trying to help another user(and failed). – David Wilson May 03 '16 at 21:42
  • @DavidWilson Yes it does. He also tells that in a code-comment. but is there a way do have a printerselection before printing? – Luke May 04 '16 at 12:19