GetStatisticsInfo throws NullReferenceException on newly created document

4 posts, 2 answers
  1. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 22 Oct 2018 Link to this post

    I need to determine if document is empty, even if the document was just created in other parts of the code. The code below throws the exception. If the commented lines are uncommented then the exception is not thrown. I could work around the problem also by carrying a flag to tell me if document was just created (and not call GetStatisticsInfo in that case). Is this exception a bug? Is there a smarter or more elegant way to determine if document is empty?

     

    var d = new RadDocument();
     
    //var p = new Telerik.WinForms.Documents.FormatProviders.Rtf.RtfFormatProvider();
    //d = p.Import(p.Export(d));
     
    var s = d.GetStatisticsInfo();

     

     

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2677 posts

    Posted 23 Oct 2018 Link to this post

    Hi Mihajlo,

    I have logged this issue on our Feedback Portal. You can track its progress, subscribe to status changes and add your comment to it here. I have also updated your Telerik Points.

    You can use the following approach to determine if the document is empty:
    var d = new RadDocument();
     
    if (d.Sections.Count > 0 && d.Sections.Last.Blocks.Count >0)
    {
        var s = d.GetStatisticsInfo();

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Mihajlo
    Mihajlo avatar
    38 posts
    Member since:
    Aug 2018

    Posted 13 Nov 2018 Link to this post

    I just stumbled upon RadDocument.IsEmpty property. It seems to be exactly what I was looking for, because I don't need statistics, but just this one information, and it does not throw an exception on brand new document. Should I use this one?
  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2677 posts

    Posted 14 Nov 2018 Link to this post

    Hello Mihajlo,

    Yes, this property can be used for this as well. It does a similar thing and checks if there are sections with content in the document.

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top