How i can get and change the file links with aspose coding?

I have a word document .docx with some linked objet. In my case there is a chart linked to an external excel .xlsx file.
I have to change the linked file with another excel file with the same strutcture. This is possibile simply opening the file with word and changing the path of the linked file from the info page (see attached file).
I can’t make the same with aspose, so the question:
HOW I CAN GET AND CHANGE THE FILE LINKS WITH ASPOSE CODING?

Hi Luca,

Thanks for your inquiry. Please use OleFormat.SourceFullName property to gets or sets the path and name of the source file for the linked OLE object. Please see the following code snippet for your kind reference.

Document doc = new Document(MyDir + "oleTest.docx");
Shape shape = (Shape)doc.GetChild(NodeType.Shape, 0, true);
if (shape.OleFormat != null && shape.OleFormat.IsLink)
{
    string filePath = shape.OleFormat.SourceFullName;
    shape.OleFormat.SourceFullName = MyDir + "Excel.xlsx";
}
doc.Save(MyDir + "out.docx");

sorry, your code dont work.
shape result in null value.
I tried also with this code but maybe there is no shapes in the document:

Aspose.Words.NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); 
foreach (Shape shp in shapes )
{
    Console.WriteLine(shp.OleFormat.SourceFullName);
} 

in fact: shapes.count = 0
i also tried whith ‘fields’ but there is no field.
How i can get these object?
I tried to paste excel chart in word in different manner (as link, as image, …) but without success, possibly aspose don’t support ole objects?

Hi Luca,

Thanks for your inquiry. Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Thank you in advance!!!
The docx attached contain 2 object linked on excel file ‘BIL_RIC_2012_A_80.xls’, i want change the object linked to another file, ‘BIL_RIC_2013_A_80.xls’
1- link to a range of cells (it function changing fields object)
2- link to a chart (this is the problem)
here the code :

string oldname = @"BIL_RIC_2012_A_80.xls";
string newname = @"BIL_RIC_2013_A_80.xls";
Aspose.Words.Document doc = new Aspose.Words.Document("test_link.docx");

/* not functioning
* Shape shape = (Shape)doc.GetChild(NodeType.Shape, 1, true);
if (shape.OleFormat != null && shape.OleFormat.IsLink)
{
string filePath = shape.OleFormat.SourceFullName;
shape.OleFormat.SourceFullName = filePath.Replace(oldname, newname);
}*/
// list of all shapes - no shapes found
Aspose.Words.NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);

foreach (Shape shp in shapes)
{
    Console.WriteLine(shp.OleFormat.SourceFullName);
}
// this function and allow change field link
Aspose.Words.NodeCollection fields = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart fld in fields)
{
    if (fld.FieldType.Equals(FieldType.FieldLink))
    {
        Run code = (Run)fld.NextSibling;
        code.Text = code.Text.Replace(oldname, newname);
        doc.UpdateFields();
    }

}
doc.Save("testout.docx");

Hi Luca,

Thanks for sharing the details. Please use the following code snippet to achieve your requirements. Hope this helps you. Please let us know if you have any more queries.

string oldname = @"BIL_RIC_2012_A_80.xls";
string newname = @"BIL_RIC_2013_A_80.xls";
// Open document
Document doc = new Document(MyDir + "test_link.docx");
Aspose.Words.NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
Aspose.Words.NodeCollection fields = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart fld in fields)
{
    if (fld.FieldType.Equals(FieldType.FieldLink))
    {
        Node currentNode = fld.NextSibling;
        while (currentNode.NodeType != NodeType.FieldSeparator)
        {
            Node nextNode = currentNode.NextSibling;
            if (currentNode.NodeType == NodeType.Run)
                (currentNode as Run).Text = (currentNode as Run).Text.Replace(oldname, newname);
            currentNode = nextNode;
        }
    }
}
doc.UpdateFields();
doc.Save(MyDir + "out.docx");