We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Error when trying to select text

Thread ID:

Created:

Updated:

Platform:

Replies:

105281 Sep 25,2012 03:47 PM UTC Sep 27,2012 09:47 AM UTC ASP.NET Web Forms (Classic) 1
loading
Tags: DocIO
Administrator [Syncfusion]
Asked On September 25, 2012 03:47 PM UTC

I am getting the following error when trying to select text from a document:

m_itemEndIndex is less than 0 or greater than 6
Parameter name: m_itemEndIndex

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: m_itemEndIndex is less than 0 or greater than 6
Parameter name: m_itemEndIndex

I am simply trying to select all the text in a word document using the following code:

WordDocument replaceDoc = new WordDocument();

replaceDoc.Open(@"Test.doc", FormatType.Doc);

TextBodyPart replacePart = new TextBodyPart(replaceDoc);

replacePart = new TextBodyPart(replaceDoc);

TextBodySelection textSel = new TextBodySelection(replaceDoc.LastSection.Body, 0, replaceDoc.LastSection.Paragraphs.Count, 0, 1);

replacePart.Copy(textSel);

 

 

I get the error on the line:

TextBodySelection textSel = new TextBodySelection(replaceDoc.LastSection.Body, 0, replaceDoc.LastSection.Paragraphs.Count, 0, 1);

 

Could some one help me?  How can I select all the text in a document?

 

Thanks

 

 

 


Ramkumar M [Syncfusion]
Replied On September 27, 2012 09:47 AM UTC

Hi Juan,

Thank you for your interest in Syncfusion products.

On analyzing your code snippets we found that you have provided itemEndIndex parameter value in TextBodySelection constructor as replaceDoc.LastSection.Paragraphs.Count. It must be replaceDoc.LastSection.Paragraphs.Count-1 to define the index of last paragraph in Paragraphs collection. For your reference we have modified your code snippets. Please find the code snippets below and let us know if it helps you

Code snippets:

WordDocument replaceDoc = new WordDocument();

replaceDoc.Open(@"Test.doc", FormatType.Doc);

TextBodyPart replacePart = new TextBodyPart(replaceDoc);

replacePart = new TextBodyPart(replaceDoc);

 

TextBodySelection textSel = new TextBodySelection(replaceDoc.LastSection.Body, 0, replaceDoc.LastSection.Paragraphs.Count-1, 0, 1);

 

replacePart.Copy(textSel);

 

Please let us know if you have any question.

Regards

Ramkumar


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;