Associating CustomXml with a Headerpart

I am in this with this problem. I can successfully bind xml to the main body of the document, however I cannot force the content controls in the header to bind to xml.

AddCustomXmlPart does not seem to exist for the Headerpart, and if I try to add CustomXmlPart via hdrpart.AddPart (xmlPart);

I get an invalid operation exception. "Part cannot be added here" and cannot use hdrpart.AddNewPart (); since CustomXmlPart is not an IFixedContentTypePart element.

I have spent the last few days looking for examples of how to bind data to a header, but all of this has no effect. There are many examples of creating new headers, moving headers, etc., but nothing has to do with binding CustomXml to the header.

Hope someone can shed some light on this.

Thanks in advance.

Al

+3
source share
1 answer

take a look at the implementation using a reflector. There you can see that MainDocumentPart defines some restrictions regarding the parts that can be added. These definitions are made in the GetPartConstraint () method (this method is derived from OpenXmlPartContainer).

GetPartConstraints() MainDocumentPart , CustomXmlPart. GetPartConstraints() HeaderPart , CustomXmlPart. → .

, .

.

+2

Source: https://habr.com/ru/post/1735165/


All Articles