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

Import from word issue

3 Answers 28 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
yiping
Top achievements
Rank 1
yiping asked on 20 Jul 2016, 09:58 AM

When I import the word file attached, it has a stackOverFlow exception when I running following code 

            foreach (var section in document.Sections)
            {
                document.CaretPosition.MoveToEndOfDocumentElement(section);
                editor.ChangeSectionColumns(SectionColumnsLayout.One);
            }

Is there any way to solve it, or how can I modify the word file to avoid the crash?

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 22 Jul 2016, 10:45 AM
Hi Yiping,

Indeed I was able to reproduce a StackOverflowException, but it is caused because of a known issue, related to Bookmarks. Here is the related item in our feedback portal, for which you could vote and subscribe. In this way, you will be notified about any changes related to it.

Further, I've edited the sent file by removing the bookmarks causing the exception and I've tried to reproduce the problem with the sent code-snippet, but to no avail. Everything works as expected.

If you have further questions, please get back to us again.

Regards,
Todor
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
yiping
Top achievements
Rank 1
answered on 25 Jul 2016, 03:09 PM
How can I find out the word document will have this issue? This file can successfully imported as a RadDocument, is there any property I can find in the radDocument to show some warning information instead of StackOverflow and terminate the program?
0
Todor
Telerik team
answered on 27 Jul 2016, 08:40 AM
Hi Yiping,

Unfortunately, there isn't a way to obtain an information which shows that a given document contains such bookmarks before its measuring or without opening the XML parts of the file and examine the markup. However, for that specific document, you could remove all the Bookmarks after its import and in this way, the document could be opened:
private void richTextBox_DocumentChanged(object sender, EventArgs e)
{
    foreach (BookmarkRangeStart bmkStart in this.richTextBox.Document.EnumerateChildrenOfType<BookmarkRangeStart>().ToList())
    {
        bmkStart.Parent.Children.Remove(bmkStart);
    }
}

Please note, that the above code snippet will remove all the Bookmarks in the document, not only those which are causing the issue.

Regards,
Todor
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
yiping
Top achievements
Rank 1
Answers by
Todor
Telerik team
yiping
Top achievements
Rank 1
Share this question
or