I have an application that generates Open XML documents with Content Controls.
To create a new Content Control I use Interop and the method ContentControls.Add
. This method returns an instance of the added Content Control.
I have some logic that saves the id of the Content Control to reference it later, but in some computers I've been having a weird problem.
When I access the ID property of the Content Control I just created, it returns a string with the numeric id, the problem is that when this value is too big, after I save the document, if I look through the document.xml in the generated document, the <w:id/>
element of the <w:sdtPr/>
element has a negative value, that is the signed equivalent of the value I got from the Id
property of the generated control.
For example:
var contentControl = ContentControls.Add(...);
var contentControlId = contentControl.ID;
// the value of contentControlId is "3440157266"
If I save the document and open it in the Package Explorer, the Id
of the Content Control is "-854810030" instead of "3440157266".
What have I figured out is this:
((int)uint.Parse("3440157266")).ToString() returns "-854810030"
Any idea of why this happens? This issue is hard to replicate because I don't control the Id
of the generated controls, the Id
is automatically generated by the Interop libraries.