Add-in to add 2 attributes to every element in a form - InfoPath Dev
in

InfoPath Dev

Add-in to add 2 attributes to every element in a form

Last post 01-21-2008 02:11 PM by rmacmorran. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 01-21-2008 01:30 PM

    Add-in to add 2 attributes to every element in a form

    I have a bunch of forms that I need to update in design mode to include 2 attributes to each element/control (whatever is the correct term).  I have built an add-in that shows the menu item under Tools, but on click, it opens a new, empty InfoPath app window.

     

    Here is the code I tried:

    private void ContactFormMenuItem_Click(Office.CommandBarButton ctrl, ref bool CancelDefault)

    {

    XmlDocument xDoc = null;

    try

    {

    xDoc = (
    XmlDocument)app3.XDocuments[0];

    }

    catch (Exception ex)

    {

    string s = "";

    }

    foreach (System.Xml.XmlNode node in xDoc.SelectNodes("//*"))

    {

    if (node.NodeType == XmlNodeType.Element)

    {

    XmlAttribute attID = xDoc.CreateAttribute("ID");XmlAttribute attSourceID = xDoc.CreateAttribute("SourceID");

    node.Attributes.Append(attID);

    node.Attributes.Append(attSourceID);

    }

    }

    }

     

     

    Basically, it fails on the "xDoc = " line because there aren't any XDocuments because it opened a new window.

  • 01-21-2008 02:08 PM In reply to

    Re: Add-in to add 2 attributes to every element in a form

    I tried to get to your document through its parent Window object.  I accessed some read-only properties just to see if I could get in, but Ireceived the following errors:

     

    ?this.Application.Windows[0].XDocument.DOM

    '((Microsoft.Office.Interop.InfoPath.Window2)(this.Application.Windows[0])).XDocument' threw an exception of type 'System.InvalidCastException'

    base {System.SystemException}: {"InfoPath has encountered an error. The operation failed.\n\nDocument object cannot be accessed.\nNo such interface supported\r\n"}

     

    ?this.Application.Windows[0].XDocument.DataObjects.Count

    '((Microsoft.Office.Interop.InfoPath.Window2)(this.Application.Windows[0])).XDocument' threw an exception of type 'System.InvalidCastException'

    base {System.SystemException}: {"InfoPath has encountered an error. The operation failed.\n\nDocument object cannot be accessed.\nNo such interface supported\r\n"}

     

    ?this.Application.Windows[0].XDocument.DataAdapters.Count

    '((Microsoft.Office.Interop.InfoPath.Window2)(this.Application.Windows[0])).XDocument' threw an exception of type 'System.InvalidCastException'

    base {System.SystemException}: {"InfoPath has encountered an error. The operation failed.\n\nDocument object cannot be accessed.\nNo such interface supported\r\n"}

     

  • 01-21-2008 02:11 PM In reply to

    Re: Add-in to add 2 attributes to every element in a form

    What larko_s was really trying to say (I talked to him about it offline) was that he wants to modify the schema to allow attributes to be added. 

    (forgive me for putting words into your mouth)

     

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.