Hello,
You have an exception during de-serialization in
System.Drawing.Printing.PrinterSettings.set_PrintFileName(String value)
because it is not allowed to set the property
PrintFileName
to an empty or null string, the setter of the property throws this exception.
I go round this issue by assigning a fake file name to the property, it is not a problem as it is unused if PrintTofile is False.
PrinterSettings prtSettings = new PrinterSettings();
prtSettings.PrintFileName = "does not matter, unused if PrintToFile == false";
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(prtSettings.GetType());
using (System.IO.TextWriter txtWriter = new StreamWriter(@"c:\temp\printerSettings.xml"))
{
xmlSerializer.Serialize(txtWriter,prtSettings);
}
using (FileStream fileStream = new FileStream(@"c:\temp\printerSettings.xml", FileMode.Open))
{
object obj = xmlSerializer.Deserialize(fileStream);
prtSettings = (PrinterSettings)obj;
}
Valery.