Inserting a linked-only image into a doc

(Using Aspose 4.3.1)

Hi Aspose,

I can’t manage to insert a purely linked image form scratch. It looks like it always ends up in an embedded image. I use some code like

Aspose.Words.Document doc = new Aspose.Words.Document();
Aspose.Words.Drawing.Shape newShape = new Aspose.Words.Drawing.Shape(doc, Aspose.Words.Drawing.ShapeType.Image);
newShape.ImageData.SourceFullName = @"C:\myImage.gif";
doc.LastSection.Body.LastParagraph.AppendChild(newShape);
doc.save("file.doc");

According to the documentation the image should then be a linked image but I can see no field in the saved doc. Instead the image is embedded.
What went wrong?

Best
Jörg

Hi
Thanks for your inquiry. You can insert linked image into the document using InsertField method. Linked imaged is INCLUDEPICTURE field. Please see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
string fieldCode = string.Format("INCLUDEPICTURE \"{0}\" \\d", @"C:\\Temp\\1.jpg");
builder.InsertField(fieldCode, null);
doc.Save(@"Test067\out.doc");

But after inserting 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.
https://support.microsoft.com/en-us/topic/the-filename-field-does-not-automatically-update-when-you-open-a-document-in-word-de2bfb95-d990-1ced-a618-5ac0a2ec1be4
Best regards.

Hello!
Thanks for your answer. I guess I found the reason: I forgot to specify the wraptype properly. After setting

newShape.WrapType = WrapType.Inline;

I could see that it was included as linked image. But maybe that is not equivalent to your code, I don’t know.
Best
Jörg

Hi
It is nice that you already found solution. The following code inserts image as INCLUDEPICTURE field.

Document doc = new Document();
Shape img = new Shape(doc, ShapeType.Image);
img.WrapType = WrapType.Inline;
img.ImageData.SourceFullName = @"C:\Temp\1.jpg";
doc.FirstSection.Body.FirstParagraph.AppendChild(img);
doc.Save(@"Test067\out.doc");

if you open your document in MS Word and press Alt+F9 you will see field codes inside your document.
Best regards.