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
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("
TextSelection SelEnd = document.Find("
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
SIGN IN To post a reply.
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
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
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
AD Administrator
- May 19, 2009 10:02 AM UTC
- May 20, 2009 12:53 PM UTC