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. Image for the cookie policy date
close icon

Insert BookmarkEnd into Section.ChildEntities

Hi,

I need to delete content between two paragraphs in a word document. I can Identify the paragraphs and have inserted the bookmark start before the first paragraph.

If the second paragraph is in the same seciton as the first, then I want to insert the bookmarkend before the second paragraph. If not then I want to insert the bookmarkend as the last item in the section. My aim is to delete the first paragraph and everything following it until (but excluding the second paragraph).

I tried the following:
int stopEntityIndex = -1;
try
{
stopEntityIndex = section.ChildEntities.IndexOf(secondParagraph);
}
catch(ArgumentOutOfRangeException)
{

}

if (stopEntityIndex == -1)
{
stopEntityIndex = section.ChildEntities.Count - 1;
}

BookmarkEnd end = new BookmarkEnd(outDoc,"bkmark");
section.ChildEntities.Insert(stopEntityIndex , end as Entity);

My problem is that I get a System.InvalidOperationException when I try to insert saying {"Cannot insert an object to SectionChildEntities collection."}


4 Replies

VS Vijayakumar S Syncfusion Team September 24, 2009 07:24 AM UTC

Hi Motunrayo,

Thank you for using Syncfusion products.

We have prepared a sample to achieve your requirement. Could you please have a look at the sample in the below link which inserts the bookmarkstart and bookmarkend for your requirement and delete the contents of the bookmark. Please try running this sample and let us know if this helps.

sample: http://files.syncfusion.com/support/DocIO.Windows/F90238/F90238.zip

Please let us know if you have any questions.

Regards,
Vijay


MO Motunrayo Ogunyinka September 24, 2009 09:13 AM UTC

Thanks for that, I've got it to work now


VS Vijayakumar S Syncfusion Team September 24, 2009 09:39 AM UTC

Hi Motunrayo,

Thank you for your update.

Please let us know if you have any questions.

Regards,
Vijay


CS Charulatha Suryakumar July 18, 2014 09:18 AM UTC

Hi Vijaykumar,

Please send me the attachment, I cant get it on the link which you gave. I also want the code to insert childentities on the section

Got the same issue "Cannot insert an object to SectionChildEntities collection."

Regards
Charulatha Suryakumar

Loader.
Live Chat Icon For mobile
Up arrow icon