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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Fetching & then deleting content between 2 strings

Thread ID:





81331 May 19,2009 10:02 AM UTC May 20,2009 12:53 PM UTC WinForms 1
Tags: DocIO
Administrator [Syncfusion]
Asked On May 19, 2009 10:02 AM UTC


I am trying to fetch the contents between 2 tags, for example as below:

I have some text written here
Then I have a table

(Please see the attachment for the template)

Now I am trying to fetch the contents between these tags, once I fetch the contents, I want to delete the contents between these tags including the tags, so that I only have the text & the table left for the new document. My problem is that I am not able to delete the contents between the 2 tags after fetching them, please find below the code which I am using to fetch the contents. PLEASE HELP ME TO DELETE THE CONTENTS BETWEEN THE TAGS.

private void Save()
WordDocument document = new WordDocument(Server.MapPath("~/test.doc"),FormatType.Doc);
WordDocument docMaster = new WordDocument(Server.MapPath("~/dummy.doc"),FormatType.Doc);

TextSelection SelBegin = document.Find("", true, true);
TextSelection SelEnd = document.Find("", true, true);

WParagraph paraStart = SelBegin.GetAsOneRange().OwnerParagraph;
SelBegin.GetAsOneRange().Text = SelBegin.GetAsOneRange().Text.Replace(SelBegin.GetAsOneRange().Text, String.Empty);

WParagraph paraEnd = SelEnd.GetAsOneRange().OwnerParagraph;
SelEnd.GetAsOneRange().Text = SelEnd.GetAsOneRange().Text.Replace(SelEnd.GetAsOneRange().Text, String.Empty);

TextBodyPart BodyPart = new TextBodyPart(document);
TextBodySelection BodySel = new TextBodySelection(paraStart.Items[0], paraEnd.Items[paraStart.Items.Count - 1]);


//I want to delete the contents of BodySel

document.Save(Server.MapPath("~/test.doc"), FormatType.Doc);
docMaster.Save(Server.MapPath("~/dummy.doc"), FormatType.Doc);



Bhuvaneswari P [Syncfusion]
Replied On May 20, 2009 12:53 PM UTC


Thank you for your interest in Syncfusion products.

I am afraid I am unable to reproduce the issue. I have created sample using your code and used your document to replace the content. Its works as expected. It removes the begin and end tags and its content.

Here is the sample for your reference:

Please have a look into the sample and the output documents from the sample [..output\test.doc and output\dummy.doc]. Please try to reproduce the issue in it and send the same. Also please provide your Office version and Essential Studio version details. This would help us to investigate the issue further.

Best Regards,


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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