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

Fetching & then deleting content between 2 strings

Hi

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]);

BodyPart.Copy(BodySel);
BodyPart.PasteAfter(docMaster.Sections[0].Paragraphs[0]);

//I want to delete the contents of BodySel

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

Thanks
Mark



test_8992f848.doc

1 Reply

BP Bhuvaneswari P Syncfusion Team May 20, 2009 12:53 PM UTC

Hi,

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:
http://files.syncfusion.com/samples/DocIO.windows/DocIO81331.zip

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,
Bhuvana

Loader.
Live Chat Icon For mobile
Up arrow icon