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

Free Support Forum - aspose.com

Update field links in Word doc

How do I update links in a Word doc? Using the Office Excel Interop library I was able to do it this way:
word_application.ActiveDocument.Fields[1].LinkFormat.SourceFullName = sourceFile
word_application.ActiveDocument.Fields[2].LinkFormat.SourceFullName = sourceFile

The code is in Python, but that’s OK, ignore the syntax, I’m looking for the correct method/params to do this and I cannot find the equivalences in Aspose.Words docs.

Thanks!
-rob

@rkoch1,

Thanks for your inquiry. Please use OleFormat.SourceFullName property to get or set the path and name of the source file for the linked OLE object. Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);

if (shape.OleFormat != null)
{
    shape.OleFormat.SourceFullName = MyDir + "new document.xlsx";
}
doc.Save(MyDir + "17.8.docx");

I see the SourceFullName is updated when I open the document and when I checked the Link Properties in Word it has the updated link so that piece works. However, the object is still referencing the templated/older chart.What would be the way to refresh the OLE object or when you’re in Word you can go to File > Info > Edit Links to Files > Update Now?

document.UpdateFields() didn’t do anything.

Then… after the objects are refreshed, I’d like to break the links – using the Office library, I could do this:
word_application.ActiveDocument.Fields[1].LinkFormat.BreakLink()

Thanks.

@rkoch1,

Thanks for your inquiry. Please use OleFormat.AutoUpdate property to specify whether the link to the OLE object is automatically updated or not in Microsoft Word. We suggest you please set the value of this property as true.

If you still face problem, please share your input, output and expected output Word documents along with code example to reproduce your issue at our end. We will investigate the issue on our side and provide you more information.

Here’s the code we used:

            var license = new Aspose.Words.License();
            license.SetLicense(@"Aspose.Total.lic");
            var wordDocPath = @"Template.docx";
            var excelWbPath = @"Format.xlsx";
            Console.WriteLine("Starting test.");
            Console.WriteLine("Now updating...");
            var document = new Document(wordDocPath);
            var shape = (Shape)document.GetChild(NodeType.Shape, 0, true);
            shape.OleFormat.SourceFullName = excelWbPath;

            var shape2 = (Shape)document.GetChild(NodeType.Shape, 1, true);
            shape2.OleFormat.SourceFullName = excelWbPath;

            document.Save("Final.docx");

            Console.WriteLine("Completed. File is at Final.docx");
            Console.ReadLine();

I redid this in C# and was able to replicate my problem. Clearly Aspose.Words piece that updates OLE Objects are broken. Word doc comes up asking me to update link. I said no, while the chart still isn’t updated. Plus, I am not sure if there’s a “Break Link” functionality or not.

Also how shall I send you my sample project?

Thanks!
-rob

@rkoch1,

Please ZIP and attach your input Word and Excel documents here for testing. We will investigate the issue on our side and provide you more information.