Solved

Saving Printer Settings

Posted on 2010-09-13
3
848 Views
Last Modified: 2012-05-10
I am using the PrintDialog class in c# to display the printer setup dialog so that the user can modify the printer settings.  How do you save the printer settings to a text file?
0
Comment
Question by:harry12
3 Comments
 
LVL 13

Expert Comment

by:copyPasteGhost
ID: 33664139
0
 
LVL 16

Accepted Solution

by:
kris_per earned 500 total points
ID: 33666008

PrinterSettings is available in PrintDialog.Document.PrinterSettings after the printing is done...Try saving the PrinterSettings object as xml using XmmlSerialiser. Sample code below:


private void button1_Click(object sender, EventArgs e)

        {

            PrintDocument pd = new PrintDocument();

            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);            

            pd.PrinterSettings.PrinterName = "HP LaserJet 1111";



            printDialog1.Document = pd; // printDialog1 was added in form designer from controls Toolbox

            printDialog1.ShowDialog();



            // printing has finished; now save PrinterSettings to xml



            StreamWriter sw = new StreamWriter("printerSettings.xml");



            XmlSerializer x = new XmlSerializer(typeof(PrinterSettings));



            x.Serialize(sw, pd.PrinterSettings);



            sw.Close();

        }



        private void pd_PrintPage(object sender, PrintPageEventArgs ev)

        {

            // do the actual document printing here

        }

Open in new window

0
 

Author Closing Comment

by:harry12
ID: 33666963
Just what I needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now