Null reference exception in using winforms and WPF edition

Posted by: ashwini.kanchan on 22 November 2018, 2:26 am EST

    • Post Options:
    • Link

    Posted 22 November 2018, 2:26 am EST

    Instance of class C1PrintOptions throwing an null reference exception.

    Code in winform edition

    C1PrintOptions options = new C1PrintOptions();

    //setting Printer

    options.PrinterSettings.PrinterName = printer

    this statement is throwing exception

    also in WPF edition

    C1PrintOptions options = new C1PrintOptions();

    option.Printqueue

    throws the same exception

    I am new in using this component pdf library, today started using this but got this exception. Need support on this

  • Posted 25 November 2018, 3:46 pm EST

    Hello,

    WinForms:

    You need to instantiate PrinterSettings before using the same with C1PrintOptions. For this, please use the below mentioned code:

    
    C1PrintOptions po = new C1PrintOptions();
    po.PrinterSettings = new PrinterSettings();
    po.PrinterSettings.PrinterName = printer;
    

    WPF:

    Similarly, an instance of PrintQueue must be defined. It can be done as:

    C1PrintOptions options = new C1PrintOptions();
    options.PrintQueue =LocalPrintServer.GetDefaultPrintQueue();  
    

    With these changes, the exception should no longer occur.

    Best Regards,

    Esha

  • Posted 2 December 2018, 7:39 pm EST

    Hello Esha,

    Thank you for your reply. Actaully I need to access another printserver not the local printserver.

    And each time the printer name will be different. For that the above method will work?

    and another thing is How I can assign names of printers on network printserver in my current code.

    Which method can be used? Is there and examples of these methods

    Waiting for reply

    Thanks again

    BR

    Ashwini

  • Posted 5 December 2018, 5:12 pm EST

    Hi Ashwini,

    >>Actaully I need to access another printserver not the local printserver.

    PrintServer class can be used to connect to any server.

    https://docs.microsoft.com/en-us/dotnet/api/system.printing.printserver?view=netframework-4.7.2

    >>And each time the printer name will be different.

    The printer names from the server can be fetched using the below mentioned code snippet. With this, the desired printer can be chosen and set for prinitng the report.

         //fetch printers 
             string queuename = "Print queues: \n";
             foreach (PrintQueue pq in pqCol)
             {
                 queuename += "\t" + pq.Name + "\n";
             }
    

    >>and another thing is How I can assign names of printers on network printserver in my current code.

    For this, you can use the InstallPrintQueue method from the PrintServer class. This helps to assign printer and thus, printer name to the print server.

    A sample is attached for your reference. You can modify the same as per your server and printer names. Also, note that the report used in the sample is bound to C1NWind.mdb shipped with the product.

    Best Regards,

    Esha

    prj_WPF_FlexReport_PrintOptions.zip

  • Posted 7 December 2018, 2:33 am EST

    Thanks Esha for your reply. One more question I have I started using the code now but I do the code like using Printeserver and then Printqueue.

    There I am using the Specific printername. It seems working fine for an Application. I got the pdf printed but when I tried to use the same thing as service then I dont get any printouts

    and I am not able to understand why? I checked the logs as well there are no error as well.

    What do you think is it because of some lincence issue. We will soon want to buy the product component one for WPF and thats why I am testing it out. We mainly want to use it for printinf service only. Can you please guide little bit in this regard.

    Thanks

    Ashwini

  • Posted 7 December 2018, 2:36 am EST

    Hi i tried to open the example file you have attached, but its not opening showing error unable to load the project.

    Thanks

    BR

    Ashwini

  • Posted 9 December 2018, 8:39 pm EST

    Hi Ashwini,

    Your issue has been responded on SupportOne ticket 356944.

    Please respond to the same.

    Regards,

    Esha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels