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

Free Support Forum - aspose.com

Adding a Link to Word Document Programmatically

I would like to add a link to a Word Document using Aspose.Words. I would like a relative link to a document that will be stored at the same level in the directory. How can this be done?

This would be the equivalent of taking the following steps in word:

Insert...

Object...

Then, in the object dialog (see attachment)

Select Create from File tab

Select Link to File

Select Display as Icon

Your assistance is appreciated.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Unfortunately there is not way to insert embedded or linked objects. But you can try inserting LINK field. See the following code example:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertField("LINK Word.Document.8 \"C:\\\\Temp\\\\in.doc\" \"\" \\a \\f 0 \\p", "doc");

doc.Save(@"Test287\out.doc");

But note that Aspose.Words doesn’t update this field so you should update fields inside the document manually (ctrl+A and F9). Also you can use macro to update fields. See the following link to learn more.

http://support.microsoft.com/kb/832897

Best regards.

Thanks for your prompt reply Alexey. What about adding a simple, relative HREF to the document? For example: Another Document. I have seen this in a .mht word file, could I reproduce this with a DocumentBuilder?

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. You can try using the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertHtml("document");

doc.Save(@"Test288\out.doc");

Best regards.