Open XML document ContentControls problem with signed id's

Posted by willvv on Stack Overflow See other posts from Stack Overflow or by willvv
Published on 2010-04-22T18:47:48Z Indexed on 2010/12/23 2:54 UTC
Read the original article Hit count: 344

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about interop

Related posts about msword