tags:

views:

52

answers:

1

I would like to print any document such as pdf,word,excel or text files in a selected printer using .net .I have got success to do such printing in the default printer .The only issue now is to print in the selected printer.

Here is the code for the printing.

public bool Print(string FilePath)
    {
        if (File.Exists(FilePath)) {
            if (ShellExecute((System.IntPtr )1, "Print", FilePath, "", Directory.GetDirectoryRoot(FilePath), SW_SHOWNORMAL).ToInt32() <= 32) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }
A: 

What file format are you testing with success to the default printer?

Its not possible to just send "any" document to a printer, generally the specific file format needs to be interpretted by an application that can read the file format then render it to a printer or a file that can be interpretted by the printer.

In most cases if you can render to a PostScript or PDF you can get its to print using a single interpretter.

Mark Redman
I am testing with PDFword and excel files.You are correct any file cannot be printed ,but if the software of that file is installed it can be printed without specifying what type of file it is.It is handled by windows only.
Thunder
The problem of printing the file is already solved as shown in the question.Only the problem of specifying the printer is remaining.
Thunder
Hi, ok, not how to specify a specific printer, but its might be worth investigating how to change the default printer before printing?
Mark Redman