Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#
Article

Windows Printing using the Shell

Rate me:
Please Sign up or sign in to vote.
1.00/5 (11 votes)
1 Nov 20041 min read 54K   929   13   9
This project describes how print files using windows programming

Introduction

We needed to have a way to perform batch printing of a list of files in windows.i was able to find a way to print non-imaging files (.doc,.xls.txt.pdf) usign the System.Diagnostics.Process function and passing the "Print" verb.However,I was having trouble to find a way to print images escpecially since XP does it using the Windows XP Photo Printing Wizard.

However,I finally found a very useful example project at MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/FotoVisionDesktop.asp).
"Photos are printed using the Windows XP Photo Printing Wizard . The wizard is implemented in the system file photowiz.dll but the custom interface is not exposed. Instead, the Windows Image Acquisition Library (WIA) from Microsoft is used that provides a COM wrapper for the printing wizard. The printing code is encapsulated in the Print class."

More information about the WIA library can be found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wiaaut/wia/wiax/overviews/gettingstartedsamples.asp

The library can be downloaded and installed from http://www.microsoft.com/downloads/details.aspx?FamilyID=a332a77a-01b8-4de6-91c2-b7ea32537e29&DisplayLang=en

Though MSDN suggest the examples are in VB and scripting languages I was able to reproduce them in C#.

hope you enjoy it!!

Notes

  1. WIA imaging toolkit is available for developers who need to develop image-enabled applications for Windows ME and XP (Service Pack 1).The WIA Automation Layer exposes features in Windows XP Service Pack 1 or later to make it easy to acquire images on digital cameras, scanners, or web cameras, and to rotate, scale, and annotate your image files.
  2. Supported image formats include PNG, JPG, GIF, BMP and TIFF. These are defined by the FormatID Constants in the WIA library

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
richardza26-Jun-09 2:14
richardza26-Jun-09 2:14 
GeneralMy vote of 1 Pin
Jacquers26-Jun-09 1:30
Jacquers26-Jun-09 1:30 
QuestionHas anybody figured out where the "printprocess" class is? Pin
leozhuca14-Jul-05 4:56
leozhuca14-Jul-05 4:56 
AnswerRe: Has anybody figured out where the "printprocess" class is? Pin
rvdt13-Oct-05 0:03
rvdt13-Oct-05 0:03 
Hi,

I was looking for the same thing today and found this in MSDN,
can be transformed to the printprocess easily

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassTopic.asp[^]

regards,
rob

using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
///
/// Shell for the sample.
///

public class MyProcess
{
// These are the Win32 error code for file not found or access denied.
const int ERROR_FILE_NOT_FOUND =2;
const int ERROR_ACCESS_DENIED = 5;

///
/// Prints a file with a .doc extension.
///

public void PrintDoc()
{
Process myProcess = new Process();

try
{
// Get the path that stores user documents.
string myDocumentsPath =
Environment.GetFolderPath(Environment.SpecialFolder.Personal);

myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc";
myProcess.StartInfo.Verb = "Print";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
catch (Win32Exception e)
{
if(e.NativeErrorCode == ERROR_FILE_NOT_FOUND)
{
Console.WriteLine(e.Message + ". Check the path.");
}

else if (e.NativeErrorCode == ERROR_ACCESS_DENIED)
{
// Note that if your word processor might generate exceptions
// such as this, which are handled first.
Console.WriteLine(e.Message +
". You do not have permission to print this file.");
}
}
}


public static void Main()
{
MyProcess myProcess = new MyProcess();
myProcess.PrintDoc();
}
}
}
GeneralMore Information Pin
Martin MacPherson20-Feb-05 11:02
Martin MacPherson20-Feb-05 11:02 
GeneralRe: More Information Pin
lynchbaby7-Apr-05 3:54
lynchbaby7-Apr-05 3:54 
GeneralRe: More Information Pin
beatsunique7-Apr-05 11:56
beatsunique7-Apr-05 11:56 
GeneralRe: More Information Pin
devikta6-May-05 10:21
devikta6-May-05 10:21 
GeneralRe: More Information Pin
Andi Oliver Ion12-Aug-07 6:08
Andi Oliver Ion12-Aug-07 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.