tags:

views:

9

answers:

0

I am trying to persist the PrinterSettings (VB.NET 3.5), but keep getting exceptions reading back in. Here is the code I am using. Works fine on other types of objects.

I have tried changing the default printer to a different printer, also used Microsoft XPS Document Writer.

I read that .NET 1.1 had a problem serializing printersettings, but was corrected in 2.0.

I am sure it is something dumb I am doing...

Dim p = New Printing.PrinterSettings
    Dim L_PrintPageSettings = New System.Drawing.Printing.PageSettings
    p = L_PrintPageSettings.PrinterSettings
    Dim objStreamWriter As New StreamWriter("C:\Product.xml")
    Dim x As New XmlSerializer(p.GetType)
    x.Serialize(objStreamWriter, p)
    objStreamWriter.Close()
    Try
        'Deserialize text file to a new object.
        Dim objStreamReader As New StreamReader("C:\Product.xml")
        Dim p2 As New Printing.PrinterSettings
        p2 = x.Deserialize(objStreamReader)
        objStreamReader.Close()
    Catch ex As Exception

    End Try