Adding a Link to Word Document Programmatically

Last post 07-10-2008, 2:20 PM by alexey.noskov. 3 replies.
Sort Posts: Previous Next
  •  07-10-2008, 10:26 AM 135087

    Adding a Link to Word Document Programmatically

    Attachment: Present (inaccessible)

    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.

     

     
  •  07-10-2008, 11:03 AM 135090 in reply to 135087

    Re: Adding a Link to Word Document Programmatically

    Hi

     

    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.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  07-10-2008, 11:54 AM 135103 in reply to 135090

    Re: Adding a Link to Word Document Programmatically

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

     

     
  •  07-10-2008, 2:20 PM 135130 in reply to 135103

    Re: Adding a Link to Word Document Programmatically

    Hi

     

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

     

    Document doc = new Document();

    DocumentBuilder builder = new DocumentBuilder(doc);

    builder.InsertHtml("<a href=\"file:///C:/Temp/in.doc\">document</a>");

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

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML