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

Free Support Forum - aspose.com

Shapes not being removed after being opened in MS WORD

I generate a docx from SSRS and then apply 2 watermarks on each page. If I run the code below to remove the shapes they are removed.

But after saving the file to disk, open it in ms word and upload it back to and run the code below the shapes are not removed.

Attached is an example edited document that was opened in ms word.

This is really urgent and need a work around or if possible a hot fix !

public static Document RemoveWatermark(AsposeWords.Document doc, string identifier)
{
    NodeCollection shapesColl = doc.GetChildNodes(NodeType.Shape, true);
    Node[] shapesArray = shapesColl.ToArray();

    for (int i = 0; i < shapesArray.Length; i++)
    {
        Shape shape = (Shape)shapesArray[i];
        if (shape.Name.Contains(identifier))
            shape.Remove();
    }

    return doc;
}

In this case the identifier variable is DRAFT and DATADETAILINFO. When debugging I can see the shape.Remove() is called however it is not removed.
I have testedd using the latest version of ASPOSE.WORDS

Hi Neil,

Thanks for your inquiry. In case you are using an older version of Aspose.Words, I would suggest you please upgrade to the latest version (v13.4.0) from here and let us know how it goes on your side.

The DrawingML represents a DrawingML shape, picture, chart or diagram in a document. The Shape represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture.
https://reference.aspose.com/words/net/aspose.words.drawing/shape/

Please try the following code snippet to remove the Shape and DrawingML nodes from document. I have not put the condition of identifier. Please check names of all Shape and DrawingML and modify the code according to your requirements.

Document doc = new Document(MyDir + "Draft_not_being_removed.docx");
Node[] shapes = doc.GetChildNodes(NodeType.Shape, true).ToArray();
foreach (Shape shape in shapes)
{
    Console.WriteLine(shape.Name);
    shape.Remove();
}
Node[] DrawingML = doc.GetChildNodes(NodeType.DrawingML, true).ToArray();
foreach (DrawingML dml in DrawingML)
{
    Console.WriteLine(dml.Name);
    dml.Remove();
}
doc.Save(MyDir + "out.docx");

Thanks,

It appears that it is not a drawingML issue. It looks like when editing in word and re-uploading Word re-adds the shape but with no name… Any ideas ?

Hi Neil,

Thanks for your inquiry.

Please set the Shape.AlternativeText and DrawingML.AlternativeText in your document and put the IF condition with 'AlternativeText ’ property instead of ‘name’. Hope this helps you. Please let us know if you have any more queries.

neilst:
It looks like when editing in word and re-uploading Word re-adds the shape but with no name.

It would be great if you please share some more detail about this scenario. Are you creating the document by using MS Word?