Cannot Open Content Control Toolkit

Topics: Developer Forum
Aug 25, 2011 at 10:18 PM

I'm using the latest OpenXML Toolkit 2.0 and create a document:

            Dim FilePath As String = "C:\OpenXMLProjects\Docs\Test.Docx"
            Using wordDocument As WordprocessingDocument = WordprocessingDocument.Create(FilePath, WordprocessingDocumentType.Document)
                wordDocument.PackageProperties.Title = "TestDoc"
                Dim mainPart As MainDocumentPart = wordDocument.AddMainDocumentPart()
                mainPart.Document = New Document()
                Dim body As Body = mainPart.Document.AppendChild(New Body())
                Dim para As Paragraph = body.AppendChild(New Paragraph())
                Dim run As Run = para.AppendChild(New Run())
                run.AppendChild(New Text("Sample Text"))
                run.AppendChild(New Text("  More Text."))
            End Using

I then open the document:

            Using docMain As WordprocessingDocument = WordprocessingDocument.Open("C:\OpenXMLProjects\Docs\Test.Docx", True)

...  define the main part and delete any customXMLparts:

                Dim docMainPart As MainDocumentPart = docMain.MainDocumentPart
                docMainPart.DeleteParts(Of CustomXmlPart)(docMainPart.CustomXmlParts)

...  then add a customXMLPart:

                Dim docCustXMLPart As CustomXmlPart = docMainPart.AddCustomXmlPart(CustomXmlPartType.CustomXml)
... and then just close out:
            End Using
Clearly, I intend to do more in the way of populating the customXML part with varying xml data from time to time.  But the above is enough to kill the Content Control Toolkit.
Though I'd like to do as much as possible programmatically, it looks to be a lot easier to link any content controls that I might add to the document to the xml in the customxml
file manually using the CCT.
But I get "Failed to open. Object reference not set to an instance of an object." wnen attempting to launch the tool. Can anyone suggest why.
Aug 26, 2011 at 11:52 AM

What happens if you open this document in Word? Can you link to the document? (or send it to me via direct message)