How to get the docPartGallery value of StructuredDocumentTag of type SdtType.DocPartObj

there are two StructuredDocumentTag of SdtType.DocPartObj, how to get the value of docPartGallery, or how to recogonize them

图片.png (1.7 KB)
图片.png (1.8 KB)

template0.zip (184.9 KB)

my requirement is check the document to see if the coverpage exists, if nonexist, then copy it from another document.

@qingyuan.ni,

Thanks for your inquiry. GlossaryDocument class represents the root element for a glossary document within a Word document. A glossary document is a storage for AutoText, AutoCorrect entries and Building Blocks.

To access building blocks, you need to load a document into a Document object. Building blocks will be available via the GlossaryDocument property. GlossaryDocument can contain any number of BuildingBlock objects. Each BuildingBlock represents one document part.

Please check the following code example. Hope this helps you. If you still face problem, please share your expected output document here for our reference. We will then provide you more information on this.

Document doc = new Document(MyDir + "template0.docx");
NodeImporter importer = new NodeImporter(doc.GlossaryDocument.Document, doc, ImportFormatMode.KeepSourceFormatting);
                
foreach (BuildingBlock buildingBlock in doc.GlossaryDocument.BuildingBlocks)
{
    if (buildingBlock.Type == BuildingBlockType.StructuredDocumentTagPlaceholderText)
    {
        Node node = importer.ImportNode(buildingBlock.FirstSection, true);
        doc.Sections.Add(node);
    }
}
                 
doc.Save(MyDir + "output.docx");

@tahir.manzoor

may you misunderstood my question, my problem has nothing with GlossaryDocument. i just want to get the value of w:val attribute which in w:docPartGallery element.

there are two DocPartObj in the template0.docx:

<w:docPartObj>
	<w:docPartGallery w:val="Cover Pages"/>
	<w:docPartUnique/>
</w:docPartObj>

<w:docPartObj>
	<w:docPartGallery w:val="Table of Contents"/>
	<w:docPartUnique/>
</w:docPartObj>

I want to know if any of them exists in the document

@qingyuan.ni,

Thanks for sharing the detail. Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-15972 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

@qingyuan.ni,
The issues you have found earlier (filed as WORDSNET-15972) have been fixed in this Aspose.Words for .NET 17.12 update and this Aspose.Words for Java 17.12 update.
Please also check the following articles:

@qingyuan.ni,

Regarding WORDSNET-15972, just to update you that we had added a new feature to get the docPartGallery Value of StructuredDocumentTag (Content Control) of Type SdtType.DocPartObj starting from the 17.12 versions of Aspose.Words for .NET and Aspose.Words for Java APIs.

Also, the behavior of the following properties was improved:

public class StructuredDocumentTag
{
    .....
    public string BuildingBlockGallery{ get; set;}
    public string BuildingBlockCategory{get; set;}
    .....
}

It is now possible to obtain the value of these properties for Markup.SdtType.DocPartObj Content Control (SDT) type. The exception was thrown in previous versions.