Attatching an XML Expansion Pack to a document programmatically

Avner writes about how to attach a smart document XML Expansion Pack to a document programmatically:

Sub AttachManifest()

    Dim Namespace As XMLNamespace
    Set Namespace = ActiveDocument.Application.XMLNamespaces.Add(“C:\Projects\SD\my.xsd, “My Schema“, “my“, True)
    Namespace.AttachToDocument (ActiveDocument)
    ActiveDocument.Application.XMLNamespaces.InstallManifest "C:\Projects\SD\manifest_signed.xml", True
     ActiveDocument.SmartDocument.SolutionURL = "C:\Projects\SD\manifest_signed.xml"
    ActiveDocument.SmartDocument.SolutionID = "My Schema"
End Sub

[This is VBA by the way]

Comments (16)
  1. Dillip Dash says:

    If i do not provide following line then what will happen?

    ActiveDocument.SmartDocument.SolutionID = "My Schema"

  2. Dillip Dash says:

    as already the expansion pack is provided with the solution id, is it needed to assign the "solutionID" here?

  3. Mark Bower says:

    Yes I believe this line of code is required.

    InstallManifest installs the artefacts specified in the manifest onto the user’s computer. Then setting SolutionURL and SolutionID attach the SmartDoc solution to the document. I understand why you are questioning this, and to be honest I haven’t tried ommitting the last line of code to see what happens. If you have time to experiment let me know what you find.

  4. Dillip Dash says:

    Can we detach xml expansion pack programmatically? Coz u know if make any change in dll or in schema, unless u reattach, u’ll not see the change in document action pane.

  5. Mark Bower says:

    Set the SolutionID and SolutionUrl properties to empty strings to remove the attached XML expansion pack

  6. Dillip dash says:

    How to put a vertical and horizontal scroll bars to a list box in smart docs?

  7. Dillip Dash says:

    If i want to refresh the Doc. actions pane after adding some data to database on click of command button in doc. actions pane what shoud i do? Coz i want that once the data saved to database , it should visible to me in the list control in document actions pane immideately.

  8. Mark Bower says:

    All the info you need is in the Office 2003 reference. The method you need is the RefreshPane method:

  9. Dillip Dash says:

    Yeah , i got this refresh pane working.But now the problem is adding scrollbars to list box control in task pane. Or to rephrase i need to

    know how to access the controls in task pane .

  10. Dillip Dash says:

    OK, i could add scroll bars to list box, also could access several properties of all the controls in document actions task pane. So no worries now.

  11. Dillip Dash says:

    Can i set focus to any smart tag content in the document from the event raised from an control in document actions pane..say from "OnCheckboxChange()" event of a check box ?

  12. Dillip Dash says:

    Can i load some controls to document action pane without asociating them to any tags in the Document?

  13. johnp says:

    Dillip – You have to either associate the control to a tag, or associate it to the entire document. Word or Excel makes the decision whether or not to call ControlCaptionFromID, not you :^(

    HOWEVER, you can always choose to hide a control by returning an empty string for a caption. Thus, if you have a control associated with the entire document, when the user changes context, ControCaptionFromID will be called. This means you can go into the document, figure out where you are and determine on your own if the control should be shown (ie, return a non-zero length caption).

    BTW, my favorite way to attach solutions is with an XSLT adding to the custom properties while spitting out WordprocessingML :^)

  14. Dillip Dash says:

    Well i wanted a richer control, so i developed the activex control and loading that.

    Now i’m facing 2 problems.

    1. After loading activex control in doc pane when i’m closing the document after saving it, it’s throwing following error in system error format and trying to recover the document.

    "Faulting application winword.exe, version 11.0.6359.0, stamp 40c8b025, faulting module unknown, version, stamp 00000000, debug? 0, fault address 0x0722d5aa."

    2. I want to distribute this smart document in a sharpoint portal site. AS to get smartdoc CASPOL should be needed to be applied properly, i need to know actual stpes to be followed so that users of the site can open the document without any problem.

  15. Wamiq says:

    Hi Mark,

    The method ‘ActiveDocument.Application.XMLNamespaces.InstallManifest’ creates a registry key in Windows registry (HKEY_CURRENT_USERSoftwareMicrosoftOfficeCommonSmart TagActions). This key contains a field called ‘Filename’ that points to the Path (C:ProjectsSD) for the Smart Document dlls.

    My Question is, if I set the SolutionID and SolutionURL properties to empty string ("") and then recall the ‘InstallManifest’ method with a different Path (C:ProjectsNewSDManifestFile.xml), the registry key is not overwriten. Hence, the next time I set SolutionID to something ("My Schema"), the smart document dlls are not loaded from the correct directory.

    To provide more information. If I open up Word 2003 and ADD a new XML Expansion Pack from a different directory, the registry key IS updated and the smart document dlls are loaded from the new directory.

    I am trying to achieve this programatically because if the User re-installs my application into a new directory I want the smart document dlls to be read from that directory. In such cases, the SolutionID remains the same and only the SolutionURL changes.

    I would very much appreciate if you could spare sometime to give me some tips/help.

    Best regards,

    Wamiq Ansari

  16. Wamiq Ansari says:

    Got it!!

    well I think this seems to work for me.

    First, I remove the installed manifest from Word 2003 and this is how i’m doin it:

    foreach (Microsoft.Office.Interop.Word.XMLNamespace l_templateNamespace in ActiveDocument.Application.XMLNamespaces)


    if (l_templateNamespace.URI == "urn:schemas-microsoft-com.office11template.WordDocSD")





    Then I simply re-attach the Smart document solution again, and this is how i do it:

    string xmlManifestPath = @"C:ProjectsSDmanifest_signed.xml";

    ActiveDocument.Application.XMLNamespaces.InstallManifest(xmlManifestPath, false);


    Wamiq Ansari

Comments are closed.

Skip to main content