<?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>Views</title><link>https://www.infopathdev.com:443/forums/42.aspx</link><description> </description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Switching Views!</title><link>https://www.infopathdev.com:443/forums/thread/26167.aspx</link><pubDate>Sat, 02 Feb 2008 16:25:06 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:26167</guid><dc:creator>omomani</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/26167.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=42&amp;PostID=26167</wfw:commentRss><description>&lt;p&gt;Hi all...&lt;/p&gt;
&lt;p&gt;I have a two-view-form!! i got that form published at sharepoint in a given document library. i want to render that form in an ASP application using XmlFormView and to benefit from multi-view feature (switching views)&lt;/p&gt;
&lt;p&gt;that form is viewed in a given view based on the value of a XML-field i created named &amp;quot;ViewName&amp;quot; and in FormEvents_Loading event in VSTA i wrote a code to switch the view based on that value&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; MyNav &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; XPathNavigator&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;MyNav = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Me&lt;/font&gt;&lt;font size="2"&gt;.MainDataSource.CreateNavigator()&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Dim&lt;/font&gt;&lt;font size="2"&gt; ViewNameValue &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;As&lt;/font&gt;&lt;font size="2"&gt; XPathNavigator = MyNav.SelectSingleNode(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;/my:myFields/my:viewName&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Me&lt;/font&gt;&lt;font size="2"&gt;.NamespaceManager)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;e.SetDefaultView(ViewNameValue.Value)&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;in&amp;nbsp;my ASPX page i have my XmlFormView control to render forms, i got instance from my two-view-form (template) and it is viewed on XmlFormView in its default view (&amp;quot;view 1&amp;quot;)... after that i put a button to save that control, i used the following code to save the form back to the document library with &amp;quot;FinalViewTest&amp;quot; name&lt;/p&gt;&lt;font size="2"&gt;
&lt;p&gt;webSite.Files.Add(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;http://sv-testforms/MultiViewsTest/FinalViewTest2.xml&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;, Encoding.Default.GetBytes(xmldoc.InnerXml.ToString), &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;True&lt;/font&gt;&lt;font size="2"&gt;)&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;i used that code coz i dont want to rely on Save button that is already existed in InfoPath plus i can give here the name i want to the form in the doc library....&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;In another ASPX page i want to render the same FinalViewTest form but in the second view &amp;quot;view 2&amp;quot; so i need to change the value of ViewName field before rendering the form because switching views code is written in FormEvents_loading event in VSTA and so&amp;nbsp;i cant switch the view unless i changed the ViewName field value before rendering the form.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;i did that by first, get the form as xml from SharePoint. second, change the value of ViewName to &amp;quot;view 2&amp;quot;. third, to upload the xmldocument once again to overwrite the original one. last step, then render the form on XmlFormView, now in FormEvents_loading event it will check the value of ViewName field and it will find it &amp;quot;view 2&amp;quot; so it will render the form in the second view!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;i got two questions regarding my case:-&lt;br /&gt;first one, for my application, the ones who design Forms and publish it to SharePoint are end-users so they have to add the code responsible of switching views before publishing! but end-users are non-technical so how would i minimize their work (i.e. have a simpler procedure to add the ViewName field, and add the code for switching views)?? can i have an add-in button in InfoPath that can do that programmatically without the need of &amp;quot;users to create ViewName field and to go to VSTA and place my code&amp;quot;?? if yes, how can i do that?&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;second one, is it quite perfect to get the form and change the value of ViewName field and then upload it back to sharepoint, everytime i need to switch the view???? is there a way to change the ViewName value programmatically without the need of these all steps (i.e. change its value while it is at SharePoint without getting and uploading again)???&lt;/p&gt;
&lt;p&gt;&amp;nbsp;i would appreciate any idea..&lt;/p&gt;
&lt;p&gt;thank you all very much :)&lt;/p&gt;
&lt;p&gt;Osama Momani&lt;font size="2"&gt;&lt;/p&gt;&lt;/font&gt;</description></item></channel></rss>