We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Improved work with FieldCodes (HYPERLINK) instead of usage of "facade" class

Hi,

in one of 2011 posts (https://forum.aspose.com/t/76806) I found that you are planning to improve processing of hyperlinks without usage of facade class.

I would say that this is not yet done? Can you please put this on ToDo list as it is weird that in all other components we can access hyperlinks and only in Words additional class is needed.

Btw. this does not work in correct way (see my post https://forum.aspose.com/t/37287).

Thanks in advance,
Oliver
dr_oli:
Hi,

in one of 2011 posts (https://forum.aspose.com/t/76806) I found that you are planning to improve processing of hyperlinks without usage of facade class.

I would say that this is not yet done? Can you please put this on ToDo list as it is weird that in all other components we can access hyperlinks and only in Words additional class is needed.

Btw. this does not work in correct way (see my post https://forum.aspose.com/t/37287).

Thanks in advance,
Oliver

Hi Oliver,


Thanks for your inquiry. We have a dedicated FieldHyperlink class now in latest versions of Aspose.Words to deal with Hyperlinks in MS Word documents. Hope, this helps.

Best regards,
Hi Awais,

this is great news. I missed that you released it on 31.01.16. :(
Do you have some coding examples to share?

Thanks,
Oliver

Hi Oliver,


Thanks for your inquiry. Please try running the following code:

// Create or load a document

Aspose.Words.Document wordDoc = new Aspose.Words.Document();

// Get first paragraph

Aspose.Words.Paragraph para = wordDoc.FirstSection.Body.FirstParagraph;

para.Runs.Add(new Run(wordDoc, "Some text. "));

// Add the hyperlink field to the paragraph

FieldHyperlink field = (FieldHyperlink)para.AppendField(Aspose.Words.Fields.FieldType.FieldHyperlink, false);

// URL

field.Address = @"""http://www.aspose.com""";

// Text

field.Result = "Go to the Aspose website";

field.Update();

// Set color of the last run

para.Runs[para.Runs.Count - 1].Font.Color = System.Drawing.Color.Blue;

// Save the document

wordDoc.Save(MyDir + @"16.1.0.docx");


Hope, this helps.

Best regards,