Click to See Complete Forum and Search --> : [RESOLVED] how to print jpg
popskie
Jul 31st, 2005, 08:52 PM
hi,
Is anyone knw how to print jpg?
Popskie
jmcilhinney
Jul 31st, 2005, 09:27 PM
You need to make sure there is an application associated with the Print action for that file type first. To check, open the Folder Options applet from the Control Panel and select the File Types tab. Scroll down to the JPG extension, click it and click the Advanced button. If there is no entry in the list for Print then you need to add one. You may also be able to achieve this through your chosen application itself.
Assuming you do have an application associated with the action you can use this code: ProcessStartInfo psi = New ProcessStartInfo(filePath);
psi.Verb = "Print";
Process.Start(psi);
where filePath is the fully qualified path to the file you want to print.
Edit:
Once you create a ProcessStartInfo object for a document, you can determine what actions you can perform in this manner by examining the Verbs property, which is an array of Strings corresponding to the list of actions you would have seen by following the instructions I gave above. This way you could write your code to check whether the user's machine has an application associated with the Print verb. If they do then you can use it but if they don't then you could just open the file and let them print it themselves. Dim psi As New ProcessStartInfo(filePath)
If Array.IndexOf(psi.Verbs, "Print") <> -1 Then
'An application is associated with the Print action so use it.
psi.Verb = "Print"
End If
'The image will be opened with the default application if there is no verb.
Process.Start(psi)
popskie
Jul 31st, 2005, 09:40 PM
Sory im not using vb. Ok i solve it.
jmcilhinney
Jul 31st, 2005, 10:02 PM
Oops. The first section is in C# but it's just in vbcode tags. I'm so used to posting in VB I did forget when I added the edit though. It's virtually exactly the same in C# anyway. I've simply added an If statement, which I'm sure you can do yourself in C#: ProcessStartInfo psi = new ProcessStartInfo(filePath);
if (Array.IndexOf(psi.Verbs, "Print") != -1)
{
// An application is associated with the Print action so use it.
psi.Verb = "Print";
}
// The image will be opened with the default application if there is no verb.
Process.Start(psi);
popskie
Jul 31st, 2005, 10:43 PM
Ok the codes was very great. thanks very much.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.