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.
Unfortunately, activation email could not send to your email. Please try again.

Hyperlinks removal

Thread ID:

Created:

Updated:

Platform:

Replies:

77765 Nov 17,2008 02:20 AM Nov 17,2008 07:11 PM Windows Forms 2
loading
Tags: DocIO
Leonardo Cavan Suryana
Asked On November 17, 2008 02:20 AM

Hi,

Currently I'm trying to open a template word document using DocIO which contains a bunch of hyperlinks that maps to the database. Now the problem I'm having is actually replacing those hyperlinks with actual data. I've manage to use checks all over my code to get all of the hyperlinks and then remove them after retrieving the values and placing a new WTextRange with the text set to the value.

My question is:
1) Is there an easier way to retrieve all of the hyperlinks that are available in a document?
2) What is the proper way of removing a hyperlink from a text? Do i have to remove the WField type (which contains the FieldType.FieldHyperlink type) and all of the text between that and a WFieldMark with type FieldEnd?

Thanks
Leo


Bhuvaneswari P [Syncfusion]
Replied On November 17, 2008 06:58 AM

Hi Leo,

Thank you for your interest in Syncfusion products.

1) Way to retrieve Hyperlinks?

Please refer the below code to retrieve the hyperlinks in the document:
foreach (Entity ent in document.ChildEntities)
{
if (ent is WSection)
{
WSection section = ent as WSection;
foreach (WParagraph paragraph in section.Body.Paragraphs)
{
for (int i = 0; i < paragraph.Items.Count; i++)
{
if (paragraph.Items[i] is WField && (paragraph.Items[i] as WField).FieldType == FieldType.FieldHyperlink)
{
Hyperlink hlink = new Hyperlink(paragraph.Items[i] as WField);
}
}
}
}
}

2) Proper way to removing a hyperlinks?
Yes, for removing the hyperlink have to remove those mentioned fields since Hyperlink consists of WField, then goes WFieldMark ( field separator ), then WTextRange ( one or several ) and then WFieldmark ( field end)

Please refer the below code snippet to remove the hyperlinks:

foreach (Entity ent in document.ChildEntities)
{
if (ent is WSection)
{
WSection section = ent as WSection;
foreach (WParagraph paragraph in section.Body.Paragraphs)
{
for (int i = 0; i < paragraph.Items.Count; i++)
{
if (paragraph.Items[i] is WField && (paragraph.Items[i] as WField).FieldType == FieldType.FieldHyperlink)
{
while (!(paragraph.Items[i] is WFieldMark &&
(paragraph.Items[i] as WFieldMark).Type == FieldMarkType.FieldEnd))
paragraph.Items.RemoveAt(i);

// Remove field end
paragraph.Items.RemoveAt(i);
break;
}
}
}
}
}


Here is the sample for your reference:
http://websamples.syncfusion.com/samples/Bookmark_77765.zip

Please let me know if this helps you.

Best Regards,
Bhuvana




Leonardo Cavan Suryana
Replied On November 17, 2008 07:11 PM

Thanks that answers my questions.


CONFIRMATION

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.

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.

;