Replace a Floating Image in Word with C# Without Changing Its Position or Size
Question details
Replace a floating image in a Word document using C# while retaining its size and position.

- Product
- Microsoft Word and Word Interop for C#
- Device & OS
- not provided
- Scenario
- A C# application needs to replace a floating Word Shape with another picture without changing its layout.
- Observed behavior
- Copying only the original shape's Top and Left values can place the replacement incorrectly because those coordinates depend on the anchor and relative-position settings.
Identify the floating Shape to replace and confirm that the replacement image file is accessible to your C# application. The approach below uses Microsoft Word Interop, not InlineShapes.
Copy the Floating Shape's Anchor and Position Settings in C#
Use Word Interop to create the replacement at the same anchor and restore its layout properties before deleting the original.
Top and Left are interpreted relative to the shape's horizontal and vertical reference settings. Set those reference settings before applying the coordinates.
In your C# code, obtain the original Word.Shape and save its Anchor.Duplicate, Width, Height, RelativeHorizontalPosition, RelativeVerticalPosition, Left, Top, and WrapFormat.Type values.
Call document.Shapes.AddPicture with the replacement file path, LinkToFile: false, SaveWithDocument: true, and the saved Anchor. Add it before deleting the original so the saved anchor remains available.
On the new Shape, set LockAspectRatio to Microsoft.Office.Core.MsoTriState.msoFalse, then apply the saved Width and Height. Set RelativeHorizontalPosition and RelativeVerticalPosition, restore WrapFormat.Type, and finally assign the saved Left and Top values.
Call Delete() on the original Shape, then open the document in Word and check the replacement's position and size. Save the document after confirming the layout.

Edit Word Documents and Replace Pictures in WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for editing Word documents and replacing pictures manually. Its Microsoft Office format compatibility helps make moving documents straightforward, although it does not fix Microsoft Word Interop automation.

Frequently Asked Questions
Why does copying Top and Left move my replacement image?
Those values depend on RelativeHorizontalPosition and RelativeVerticalPosition. Copy the reference settings and anchor first, then assign Top and Left on the new Shape.
Should I delete the original shape before adding the new picture?
You can add the replacement first using a duplicate of the original Shape's Anchor, restore its properties, and then call Delete() on the original. This keeps the original available while you capture its settings.
How do I preserve the original image dimensions?
Save the original Shape's Width and Height, set the replacement's LockAspectRatio to false, and apply both saved dimensions. This may stretch an image with a different aspect ratio.
Does this approach apply to inline pictures?
No. Inline pictures are represented by InlineShapes and behave like characters in the text. The anchor and relative-position procedure described here is for floating Shapes.




