Formatting Issues

Replace a Floating Image in Word with C# Without Changing Its Position or Size

Olivia MillerOlivia Miller Nov 27, 2026 868 views

Question details

Replace a floating image in a Word document using C# while retaining its size and position.

Replace a Floating Image in Word with C# Without Changing Its Position or Size
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.
Before you start

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.

Solution 1Recommended

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.

1
Capture the original layout

In your C# code, obtain the original Word.Shape and save its Anchor.Duplicate, Width, Height, RelativeHorizontalPosition, RelativeVerticalPosition, Left, Top, and WrapFormat.Type values.

2
Add the replacement picture

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.

3
Restore the layout properties

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.

4
Remove and check the original

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.

Copy the Floating Shape's Anchor and Position Settings in C#
Additional layout settings: If the original uses special wrapping distances, cell layout, layering, or other shape settings, copy those properties too. Later edits to the anchored paragraph can also affect the picture's position.
Free Microsoft Office alternative

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.

Replace and adjust pictures manually in WPS WriterOpen and edit Microsoft Word DOC and DOCX filesWork in a familiar, easy-to-use interfaceUse a free, lightweight Office alternative
microsoft office alternative - wps office

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.