Replace Quickpart by Bookmark

Hi,
Is there any way to replace quickpart by bookmark on the word document 2007 using Aspose.words api.
The code should find the quickpart in document and then replace it by a bookmark
Thank you
Kamel

Hi

Thanks for your request. But could you please be more specific regarding your requirement. May I know what types of fields (Quickpart) you are using inside your document? Maybe we will find other way to achieve what you need.
Best regards,

I’m using quickpart to manipulate SharePoint metadata and I’m looking for to how manipulate quickpart fields on word documents using Aspose.words Api in order to replace some existing quickparts by bookmarks
Kamel.

Hi

Thank you for additional information. As I understand, you are using StructuredDocumentTags. In this case using the latest version of Aspose.Words you can get collection of StructuredDocumentTags using the following code:

Node[] tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true).ToArray();

Then you can loop through this collection and replace all SDT with bookmarks. But there is one problem, currently there is no way to get SDT properties (like Title, Tag etc) so there is no way to identify inserted bookmark.
Your request has been linked to the appropriate issue. You will be notified as soon as the feature which allows you to get properties of STD is supported.
Best regards,

Hi

One more thing, could you please attach your document with QuickParts here for testing? It will help us in out testing. Thank you for cooperation.
Best regards,

Hi,
Here it is the word document, I would like to replace dynamically by the Aspose API like quickpart “WIP Client Code” with a new bookmark.
Thank you
Kamel

Hi

Thank you for additional information. In case of working with the attached document, I think you can try using the code like the following to achieve what you are looking for:

Document doc = new Document("MMXXXX-XXXX-45ES-XXXX+v1.0.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Get all StructuredDocumentTags
Node[] tags = doc.GetChildNodes(NodeType.StructuredDocumentTag, true).ToArray();
// Loop through all StructuredDocumentTags
foreach(StructuredDocumentTag tag in tags)
{
    // Bookmark name
    string bookmarkName = tag.ToTxt();
    // Check if parent node is Paragraph
    if (tag.ParentNode.NodeType == NodeType.Paragraph)
    {
        InsertBookmark(tag.ParentNode, builder, bookmarkName);
    }
    // If parent node is cell we should check if this call has PreviousSinling element
    else if (tag.ParentNode.NodeType == NodeType.Cell)
    {
        if (tag.PreviousSibling != null)
        {
            InsertBookmark(tag.PreviousSibling, builder, bookmarkName);
        }
        else
        {
            Cell currentCell = (Cell) tag.ParentNode;
            tag.Remove();
            currentCell.EnsureMinimum();
            InsertBookmark(currentCell.FirstParagraph, builder, bookmarkName);
        }
    }
    if (tag.ParentNode != null)
        tag.Remove();
}
doc.Save("out.docx");

Best regards,

Thank you
Kamel

The issues you have found earlier (filed as WORDSNET-4010) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(5)