<?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: 'New Record' in C#</title><link>https://www.infopathdev.com:443/forums/thread/119816.aspx</link><pubDate>Fri, 14 Sep 2018 14:25:41 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:119816</guid><dc:creator>Phani404</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/119816.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=119816</wfw:commentRss><description>Thank you. Your post helped me. :)</description></item><item><title>Re: 'New Record' in C#</title><link>https://www.infopathdev.com:443/forums/thread/103985.aspx</link><pubDate>Wed, 16 Sep 2015 19:43:11 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:103985</guid><dc:creator>ES44AC SD70MAC</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/103985.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=103985</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;well i took the time to create an account...&amp;nbsp; because i do want to let know that this is a great tip and the method presented does provide an answer to the matter presented...&lt;/p&gt;</description></item><item><title>Re: 'New Record' in C#</title><link>https://www.infopathdev.com:443/forums/thread/63401.aspx</link><pubDate>Fri, 21 Jan 2011 10:33:16 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:63401</guid><dc:creator>Drunk Goldfish</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/63401.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=63401</wfw:commentRss><description>&lt;p&gt;I&amp;#39;ve figured it out!&amp;nbsp; Yay, I&amp;#39;m happy now!&amp;nbsp; Thanks if anyone else attempted to solve the problem and I&amp;#39;ll post my solution to hopefully help anyone else that may come across this in the future:&lt;/p&gt;
&lt;p&gt;Summary Steps (InfoPath 2007 C# model)&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div&gt;Create a private string variable called &amp;#39;initialInnerXml&amp;#39; and set it to &amp;quot;&amp;quot;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Create a &amp;#39;Form Loading&amp;#39; event and within this set &amp;#39;initalInnerXml&amp;#39; equal to &amp;#39;myFields&amp;#39; innerXml&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Create&amp;nbsp;a private function/method called &amp;#39;newRecord&amp;#39; that sets &amp;#39;myFields&amp;#39; innerXml equal to &amp;#39;initialInnerXml&amp;#39;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Call this function whenever you&amp;nbsp;need to mimic the &amp;#39;New Record&amp;#39; button functionality.&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;N.B.&amp;nbsp; I&amp;#39;ve found that if you have multiple views and use the InfoPath &amp;#39;New Record&amp;#39; button, whenever you click it, the view resets to the default view.&amp;nbsp; Using this code solution, the view does not change.&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s a code example:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;public partial class FormCode &lt;br /&gt;&lt;/code&gt;&lt;code&gt;{&amp;nbsp;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This string records the initial myFields InnerXml to revert to&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private string initialInnerXml = &amp;quot;&amp;quot;; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Call this whenever you want to mimic the &amp;#39;New Record&amp;#39; InfoPath button&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void newRecord()&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Simply sets the myFields InnerXml back to what it originally was&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MainDataSource.CreateNavigator().SelectSingleNode(&amp;quot;/dfs:myFields&amp;quot;, NamespaceManager).InnerXml = initialInnerXml; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // NOTE: The following procedure is required by Microsoft InfoPath.&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // It can be modified using Microsoft InfoPath. public void InternalStartup()&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Let InfoPath create these bits for you&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ((ButtonEvent)EventManager.ControlEvents[&amp;quot;Example_Button&amp;quot;]).Clicked += new ClickedEventHandler(Example_Button_Clicked); &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This is the Form Loading event. Let infopath create it for you&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void FormEvents_Loading(object sender, LoadingEventArgs e)&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Simply records what myFields InnerXml is originally as the string initialInnerXml&amp;nbsp;&lt;br /&gt;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; initialInnerXml = MainDataSource.CreateNavigator().SelectSingleNode(&amp;quot;/dfs:myFields&amp;quot;, NamespaceManager).InnerXml; &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //This is an example button on the form that creates a new Record&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void Example_Button_Clicked(object sender, ClickedEventArgs e)&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; { &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //Call the function/method&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newRecord(); &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;} &lt;/code&gt;&lt;/p&gt;</description></item><item><title>'New Record' in C#</title><link>https://www.infopathdev.com:443/forums/thread/63316.aspx</link><pubDate>Tue, 18 Jan 2011 19:32:05 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:63316</guid><dc:creator>Drunk Goldfish</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/63316.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=63316</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;I&amp;#39;ve been scouring the internet for the latter half of the day and trying various things but I can&amp;#39;t seem to find the solution to my problem.&amp;nbsp; I&amp;#39;ve read many a post asking a similar question but unfortunately most went unanswered and those that were answered - didn&amp;#39;t help.&lt;/p&gt;&lt;p&gt;My question is basically:&amp;nbsp; &lt;b&gt;What does the button action &amp;#39;New Record&amp;#39; &lt;u&gt;actually&lt;/u&gt;&lt;i&gt; &lt;/i&gt;do in terms of coding (i.e. underlying xml document, etc)?&amp;nbsp; As a follow up to that question - how can you recreate the &amp;#39;New Record&amp;#39; action programmatically in C#?&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The basis of my problem is that I have an InfoPath 2007/2010 form that submits to an SQL table.&amp;nbsp; After the form is submitted, it needs to be cleared, ready for more data entry and submission (rinse and repeat as many times as required).&amp;nbsp; I don&amp;#39;t want the user to have to click a &amp;#39;Submit&amp;#39; button and then a &amp;#39;New Record&amp;#39; button - I figure that it should be doable in C#.&amp;nbsp; There are other reasons why I need to recreate the &amp;#39;New Record&amp;#39; functionality too but &amp;quot;the why&amp;quot; is not important so I&amp;#39;ll focus on the scenario I&amp;#39;ve just defined.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;Two of the main suggestions that I&amp;#39;ve come across are summarised below with the reason why they don&amp;#39;t help:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;After the form has submitted, query the database with an incorrect ID (i.e. -1) so that no data is returned.&amp;nbsp; Although this clears the form, it also makes it read only so it&amp;#39;s useless in the context of submitting the form again.&lt;/li&gt;&lt;li&gt;Create a load event that records the initial OuterXml as a private string value and then simply replace the OuterXml with the private string value when you need to create a new record (i.e. after submission).&amp;nbsp; This seems to work but on inspection of the SQL table I realised that every time the OuterXml is replaced and a submission is made, the previous submission is deleted/overwritten.&amp;nbsp; So if you submit 10 forms without closing the form itself down, the only submission that would remain at the end would be the last.&amp;nbsp; It&amp;#39;s more of a delete than an overwrite as the SQL key still increments by one each submission rather than just overwriting a particular row.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;I think that InfoPath points to a row in the database and even if you change various properties such as the OuterXml (or set all elements and attributes to zero, etc), it still remains pointing to the same row.&amp;nbsp; The only way it seems to move to a new row is if you add a &amp;#39;New Record&amp;#39; button to the form and click that.&amp;nbsp; &lt;/p&gt;&lt;p&gt;So in summary, I need to recreate what &amp;#39;New Record&amp;#39; does without having to dedicate a button/mouse click to it.&amp;nbsp; Any ideas? &lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>