<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Add-in to add 2 attributes to every element in a form</title><link>https://www.infopathdev.com:443/forums/thread/25790.aspx</link><pubDate>Mon, 21 Jan 2008 22:11:22 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:25790</guid><dc:creator>rmacmorran</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/25790.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=25790</wfw:commentRss><description>&lt;p&gt;What larko_s was really trying to say (I talked to him about it offline) was that he wants to modify the &lt;em&gt;schema&lt;/em&gt; to&amp;nbsp;&lt;em&gt;allow &lt;/em&gt;attributes&amp;nbsp;to be added.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;(forgive me for putting words into your mouth)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Add-in to add 2 attributes to every element in a form</title><link>https://www.infopathdev.com:443/forums/thread/25789.aspx</link><pubDate>Mon, 21 Jan 2008 22:08:20 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:25789</guid><dc:creator>rmacmorran</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/25789.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=25789</wfw:commentRss><description>&lt;p&gt;I tried to get to your document through its parent Window object.&amp;nbsp; I accessed some read-only properties just to see if I could get in, but Ireceived the following errors:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;font size="1"&gt;
&lt;p&gt;?this.Application.Windows[0].XDocument.DOM&lt;/p&gt;
&lt;p&gt;&amp;#39;((Microsoft.Office.Interop.InfoPath.Window2)(this.Application.Windows[0])).XDocument&amp;#39; threw an exception of type &amp;#39;System.InvalidCastException&amp;#39;&lt;/p&gt;
&lt;p&gt;base {System.SystemException}: {&amp;quot;InfoPath has encountered an error. The operation failed.\n﻿﻿\nDocument object cannot be accessed.\nNo such interface supported\r\n&amp;quot;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;?this.Application.Windows[0].XDocument.DataObjects.Count&lt;/p&gt;
&lt;p&gt;&amp;#39;((Microsoft.Office.Interop.InfoPath.Window2)(this.Application.Windows[0])).XDocument&amp;#39; threw an exception of type &amp;#39;System.InvalidCastException&amp;#39;&lt;/p&gt;
&lt;p&gt;base {System.SystemException}: {&amp;quot;InfoPath has encountered an error. The operation failed.\n﻿﻿\nDocument object cannot be accessed.\nNo such interface supported\r\n&amp;quot;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;?this.Application.Windows[0].XDocument.DataAdapters.Count&lt;/p&gt;
&lt;p&gt;&amp;#39;((Microsoft.Office.Interop.InfoPath.Window2)(this.Application.Windows[0])).XDocument&amp;#39; threw an exception of type &amp;#39;System.InvalidCastException&amp;#39;&lt;/p&gt;
&lt;p&gt;base {System.SystemException}: {&amp;quot;InfoPath has encountered an error. The operation failed.\n﻿﻿\nDocument object cannot be accessed.\nNo such interface supported\r\n&amp;quot;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/font&gt;</description></item><item><title>Add-in to add 2 attributes to every element in a form</title><link>https://www.infopathdev.com:443/forums/thread/25787.aspx</link><pubDate>Mon, 21 Jan 2008 21:30:58 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:25787</guid><dc:creator>larko_s</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/25787.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=25787</wfw:commentRss><description>&lt;p&gt;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).&amp;nbsp; I have built an add-in that shows the menu item under Tools, but on click, it opens a new, empty&amp;nbsp;InfoPath app window.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is the code I tried:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; ContactFormMenuItem_Click(Office.&lt;/font&gt;&lt;font color="#008080" size="2"&gt;CommandBarButton&lt;/font&gt;&lt;font size="2"&gt; ctrl, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;ref&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt; CancelDefault)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;XmlDocument&lt;/font&gt;&lt;font size="2"&gt; xDoc = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;try&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;{&lt;/p&gt;xDoc = (&lt;/font&gt;&lt;font color="#008080" size="2"&gt;XmlDocument&lt;/font&gt;&lt;font size="2"&gt;)app3.XDocuments[0];&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;catch&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#008080" size="2"&gt;Exception&lt;/font&gt;&lt;font size="2"&gt; ex)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; s = &lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;foreach&lt;/font&gt;&lt;font size="2"&gt; (System.Xml.&lt;/font&gt;&lt;font color="#008080" size="2"&gt;XmlNode&lt;/font&gt;&lt;font size="2"&gt; node &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;font size="2"&gt; xDoc.SelectNodes(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;//*&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;))&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (node.NodeType == &lt;/font&gt;&lt;font color="#008080" size="2"&gt;XmlNodeType&lt;/font&gt;&lt;font size="2"&gt;.Element)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;XmlAttribute&lt;/font&gt;&lt;font size="2"&gt; attID = xDoc.CreateAttribute(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;ID&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;XmlAttribute&lt;/font&gt;&lt;font size="2"&gt; attSourceID = xDoc.CreateAttribute(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;SourceID&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;node.Attributes.Append(attID);&lt;/p&gt;
&lt;p&gt;node.Attributes.Append(attSourceID);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Basically, it fails on the &amp;quot;xDoc = &amp;quot; line because there aren&amp;#39;t any XDocuments because it opened a new window.&lt;/p&gt;&lt;/font&gt;</description></item></channel></rss>