Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am create a windows application which need to user select the folder and this folder retrieve all file and print to my printer. In this folder many type of file such as word file, excel file, PDF file, text file etc. how are possible through in .net. please give example is available or brief idea.
Posted

Use the following code ( it will print those files which have been registered on the system with their respected application):

C#
FolderBrowserDialog fbd = new FolderBrowserDialog();
if(fbd.ShowDialog() == DialogResult.OK)
{
    foreach (var fn in Directory.GetFiles(fbd.SelectedPath)) 
    {
       var pi = new ProcessStartInfo(fn);
       pi.Verb = "Print";
 
       Process.Start(pi);
    }
}
 
Share this answer
 
v2
Well, text files should be easy.

In any case you are going to need to explore the PrintDocument Class in System.Drawing.Printing[^].

But, do you mean ... if you have a folder with one PDF file, one Excel File, and one MS Word file ... you want each of those documents printed exactly as if they were being printed from Acrobat, Excel, and Word ?

If that's what you mean, I don't think you will be able to do this for a broad range of applications. To do this you will have to "automate" those applications: launch them, send them the appropriate "messages" to tell them to print, and how to set-up the printer configuration.

Or, you will have to go with a "central hub" solution such as using 'GhostScript' the open-source PostScript converter.

If you search in CodeProject, you will certainly find articles that will help you print certain formats from .NET, for example:[^].

Another alternative may be 3rd. party components from companies, like Aspose, that specialize in these types of solutions.

And, who knows, maybe someone will respond here and show how to use Windows Script Host or something else to take this on.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900