- Home
- Forum
- ASP.NET Web Forms (Classic)
- Error when trying to select text
Error when trying to select text
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
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
Hi,
I m getting same line exception for last property -
m_pItemEndIndex is less than 0 or greater than 0 (Parameter 'm_pItemEndIndex')
TextBodyPart replaceTextBodyPart = new TextBodyPart(attachementDoc);
var section = attachementDoc.Sections[0];
var pIndex = section.Paragraphs.Count - 1;
TextBodySelection textBodySelection = new TextBodySelection(section.Body, 0, pIndex, 0, section.Paragraphs[pIndex].ChildEntities.Count -1);
According to documentation, I m using last paragraph's items count - 1.
Please help me to resolve this. I need to select all document content here.
We have tried to reproduce the reported problem using the given details with dummy document but, the reported problem was not reproduced at our end. So, could you please share the completed code example or simple issue reproducible sample along with input document to reproduce the same problem at our end and it will be more helpful for us to investigate further on your problem.
Regards,
Manikandan Ravichandran
- 3 Replies
- 4 Participants
-
AD Administrator
- Sep 25, 2012 03:47 PM UTC
- Jan 12, 2022 05:26 PM UTC