This is a migrated thread and some comments may be shown as answers.

GetStatisticsInfo throws NullReferenceException on newly created document

3 Answers 9 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Mihajlo
Top achievements
Rank 1
Mihajlo asked on 22 Oct 2018, 12:21 PM

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();

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 23 Oct 2018, 09:20 AM
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.
0
Mihajlo
Top achievements
Rank 1
answered on 13 Nov 2018, 05:13 PM
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?
0
Accepted
Dimitar
Telerik team
answered on 14 Nov 2018, 09:49 AM
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 and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextEditor
Asked by
Mihajlo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Mihajlo
Top achievements
Rank 1
Share this question
or