Import from word issue

4 posts, 0 answers
  1. yiping
    yiping avatar
    17 posts
    Member since:
    Nov 2015

    Posted 20 Jul Link to this post

    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?

  2. Todor
    Admin
    Todor avatar
    168 posts

    Posted 22 Jul Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. yiping
    yiping avatar
    17 posts
    Member since:
    Nov 2015

    Posted 25 Jul in reply to Todor Link to this post

    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?
  5. Todor
    Admin
    Todor avatar
    168 posts

    Posted 27 Jul Link to this post

    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.
Back to Top