<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DevExpertise &#187; InfoPath</title>
	<atom:link href="http://www.devexpertise.com/category/infopath/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexpertise.com</link>
	<description>Practical tips and tricks for all things .NET, SharePoint, Silverlight, InfoPath, and general application development.</description>
	<lastBuildDate>Wed, 12 May 2010 14:32:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fixing the &quot;Selected file was not found&#8221; Error When Adding an Attachment to an InfoPath Workflow Task Form</title>
		<link>http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/</link>
		<comments>http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 21:07:24 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[InfoPath]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[Features]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/</guid>
		<description><![CDATA[If you’re at all familiar with creating Visual Studio-authored workflows for SharePoint, you’re probably aware that you can also create custom task forms for tasks that have been assigned in that workflow.&#160; The task forms can either be implemented as ASP.NET forms or InfoPath forms. My personal preference is InfoPath, provided the functionality that is [...]]]></description>
			<content:encoded><![CDATA[<p>If you’re at all familiar with creating Visual Studio-authored workflows for SharePoint, you’re probably aware that you can also create custom task forms for tasks that have been assigned in that workflow.&#160; The task forms can either be implemented as ASP.NET forms or InfoPath forms. My personal preference is InfoPath, provided the functionality that is needed can be accomplished using InfoPath.&#160; By choosing InfoPath, much of the overhead required to allow SharePoint to use it as a task form is already done, whereas with ASP.NET it’s up to the developer to implement. </p>
<p>On a recent project, I had a need to create a workflow that at a certain step, prompted the user to upload a file attachment.&#160; InfoPath was the obvious choice because they’re simple to create, simple to deploy, and they even support attachments.&#160; After creating the form and the workflow I tried attaching a file to the InfoPath task form, and received the following error message:</p>
<p>&#160;<img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb.png" width="540" height="334" /></p>
<p>I searched around a little and found that this is a known issue, and there are a few ways to fix it.&#160; <a href="http://stackoverflow.com/questions/189184/the-selected-files-was-not-found-on-an-infopath-form-in-sharepoint" onclick="javascript:pageTracker._trackPageview('/outbound/article/stackoverflow.com');">This post suggests</a> adding the following bit of JavaScript to the WrkTaskIP.aspx page, which is responsible for hosting the InfoPath task form:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot;&gt;
    </span>aspnetForm.encoding = <span style="color: #a31515">&quot;multipart/form-data&quot;</span>;
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
</div>
<p>Another approach documented here suggests modifying the application.master master page file to add the necessary enctype form tag:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">form </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">onsubmit</span><span style="color: blue">=&quot;return _spFormOnSubmitWrapper();&quot; </span><span style="color: red">enctype</span><span style="color: blue">=&quot;multipart/form-data&quot;&gt;
  </span>...
<span style="color: blue">&lt;/</span><span style="color: #a31515">form</span></pre>
</div>
<p>While both of these approaches work, I wasn’t completely happy with modifying out-of-the-box SharePoint files, which isn’t recommended anyways.&#160; I took a slightly more involved, but much more reusable approach. Any customization you make to SharePoint really should be implemented as a Feature.&#160; I’m not going to go into the nuts and bolts of what features are, but you can learn a little more about them from this <a href="http://www.devexpertise.com/2009/04/01/integrating-a-custom-aspnet-application-into-sharepoint-part-4/" >previous post</a>.&#160; Before I explain my approach, here are your options for accomplishing this:</p>
<ol>
<li>Modify the out-of-the-box application.master master page file on the file system.&#160; Not recommended. </li>
<li>Modify the out-of-the-box WrkTaskIP.aspx page on the file system.&#160; Not recommended. </li>
<li>Create a new task content type, create a copy of WrkTaskIP.aspx and rename it, add the JavaScript to that page, associate the new ASPX page to your new content type, then point your workflow task forms to that new content type.&#160; Not impossible, better than the above approaches, but still a lot of unnecessary work. </li>
<li>Create a user control with the necessary script and deploy it as a delegate control feature.&#160; Recommend, and the approach I describe in this post. </li>
</ol>
<p>I decided to go with JavaScript, because I knew I could insert that into a page a lot easier than I could insert a form tag attribute.&#160; Using an approach I’ve used before on previous projects, I decided to implement this using the delegate control pattern.&#160; Take a look <a href="http://www.sharepointnutsandbolts.com/2007/06/using-delegate-control.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.sharepointnutsandbolts.com');">here</a> and <a href="http://msdn.microsoft.com/en-us/library/ms463169.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">here</a> first for a primer on delegate controls, but basically what they allow you to do is insert custom user or server controls into a place holder in the master page using a feature.&#160; This is perfect, because you can add functionality to all site pages immediately without actually modifying a single page.</p>
<p>The first step is creating the user control that will be responsible for adding the encoding to the form.&#160; I took a little different approach here too, and used jQuery to attach the encoding element to the forms. Obviously this implies that the jQuery library is being referenced already.&#160; There are other solutions that make this a cinch to accomplish, <a href="http://www.codeplex.com/smarttools/Wiki/View.aspx?title=jQuery" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">such as this one</a> by the great Jan Tielens.&#160; In fact, this solution uses the exact same approach that I’m blogging about here.&#160; My DevExpertise.TaskFormEncoding.ascx user control looks like this:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Control </span><span style="color: red">Language</span><span style="color: blue">=&quot;C#&quot; </span><span style="color: red">ClassName</span><span style="color: blue">=&quot;DevExpertiseTaskFormEncoding&quot; </span><span style="background: #ffee62">%&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot; &gt;
    </span>$(document).ready(<span style="color: blue">function</span>() {
        $(<span style="color: #a31515">&quot;form&quot;</span>).each(<span style="color: blue">function</span>(i) {
            <span style="color: blue">this</span>.encoding = <span style="color: #a31515">&quot;multipart/form-data&quot;</span>;
        });
    });
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
</div>
<p>Now that I have the user control created, I need to create a SharePoint feature to insert this into a delegate control placeholder.&#160; Both the default.master page and application.master pages that SharePoint use by default have a delegate control named AdditionalPageHead, which is there specifically for this purpose – to add script, CSS references, etc. to the page’s HEAD section:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">DelegateControl </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">ControlId</span><span style="color: blue">=&quot;AdditionalPageHead&quot; </span><span style="color: red">AllowMultipleControls</span><span style="color: blue">=&quot;true&quot;/&gt;</span></pre>
</div>
<p>The following snippet is my feature.xml file, which defines the feature.&#160; This file is responsible for specifying the feature ID, Title, Description, etc., plus any element manifests that our feature requires:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot; <span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">Feature </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/sharepoint/</span>&quot;
         <span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">2D597698-5FBC-482a-BA0F-2E42DEA2E8E4</span>&quot;
         <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise InfoPath Workflow Task Form Encoding</span>&quot;
         <span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">Adds the necessary form encoding to allow attachments
                      to be added to InfoPath workflow task forms.</span>&quot;
         <span style="color: red">Scope</span><span style="color: blue">=</span>&quot;<span style="color: blue">Site</span>&quot;
         <span style="color: red">Version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0.0.0</span>&quot;
         <span style="color: red">ImageUrl</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise\devexpertiseLogo.png</span>&quot;<span style="color: blue">&gt; 

  &lt;</span><span style="color: #a31515">ElementManifests</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">ElementManifest </span><span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">elements.xml</span>&quot; <span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">ElementManifests</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Feature</span><span style="color: blue">&gt;</span></pre>
</div>
<p>This feature is expecting an elements.xml manifest file, which is responsible for wiring up my custom user control to the AdditionalPageHead delegate control in the master page:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot; <span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">Elements </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/sharepoint/</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">Control
    </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">AdditionalPageHead</span>&quot;
    <span style="color: red">ControlSrc</span><span style="color: blue">=</span>&quot;<span style="color: blue">~/_controltemplates/DevExpertise/DevExpertise.TaskFormEncoding.ascx</span>&quot;
    <span style="color: red">Sequence</span><span style="color: blue">=</span>&quot;<span style="color: blue">10</span>&quot;<span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">Elements</span><span style="color: blue">&gt;</span></pre>
</div>
<p>The only thing left is packaging everything up and deploying it. I always package my features up into solution packages using <a href="http://www.codeplex.com/wspbuilder" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">WSPBuilder</a>, since a solution package can be used to deploy other feature-dependant files to SharePoint’s 12 folder structure. My entire solution folder structure looks like this:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb_3.png" width="365" height="278" /></p>
<p>Create the solution package, deploy it to SharePoint, and you will have a site collection feature ready for activation:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb_4.png" width="685" height="84" /></p>
<p>That’s it!&#160; Now you can successfully add attachments:</p>
<p><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb_5.png" width="494" height="261" /></p>
<p>You may be asking yourself why I went through all that trouble just to add a couple lines of JavaScript to my pages, when I could’ve just opened application.master and thrown it in there.&#160; Well, it’s not a recommended best practice to modify system files.&#160; If an update or service pack is installed that overwrites these files, then all your modifications are gone.&#160; In addition, a change like that would have to be made to all web front-end servers in your farm.&#160; This approach is extremely reusable – I can take this solution package and activate it in any site collection in any farm and I have the necessary functionality.</p>
<p>I’m feeling generous today and decided to include the solution package for your downloading pleasure.&#160; As always, it comes as-is and without warranty:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:1f9bc649-da19-462c-af64-7be97240801b" class="wlWriterEditableSmartContent">
<p>Download: <a href="http://www.devexpertise.com/wp-content/uploads/FixingtheSelectedfilewasnotfoundErrorWhe_B431/DevExpertise.TaskFormEncoding.wsp"  target="_blank">DevExpertise.TaskFormEncoding.wsp</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating a Wizard-Style Browser-Enabled InfoPath Form</title>
		<link>http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/</link>
		<comments>http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 14:34:21 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[InfoPath]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/</guid>
		<description><![CDATA[InfoPath is a great tool when you need to build simple data-entry forms.&#160; Although the tool is clearly limited when it comes to creating a rich user interface with complex controls, there are things you can do to enhance the experience if you’re creative.
One of the ways various applications collect data is through the familiar [...]]]></description>
			<content:encoded><![CDATA[<p>InfoPath is a great tool when you need to build simple data-entry forms.&#160; Although the tool is clearly limited when it comes to creating a rich user interface with complex controls, there are things you can do to enhance the experience if you’re creative.</p>
<p>One of the ways various applications collect data is through the familiar wizard-style interface.&#160; A wizard can be great if you need to collect a lot of information from user, but want to break it down into manageable chunks.&#160; At first glance, InfoPath does not support such a thing, as there isn’t a fancy wizard control like there is in ASP.NET.&#160; Luckily InfoPath allows us to create views, which provide a completely different display for the fields defined in the form.&#160; With a little code and finesse, we can successfully implement a wizard-style browser-enabled InfoPath form.&#160; The end result looks like the following:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image44.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="506" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb42.png" width="724" border="0" /></a> </p>
<p>The first thing to do is define the fields that are required in the form.&#160; For the sake of this post, I built a very simple New User Wizard with a few fields, but in the real world a wizard is better suited for collecting a lot of data:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image45.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="284" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb43.png" width="276" border="0" /></a> </p>
<p>Now that the fields are defined, a view needs to be created for each “page” of the wizard.&#160; In this case, I created 2 views in addition to the default view, and also renamed the default view to page1:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image46.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="213" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb44.png" width="276" border="0" /></a> </p>
<p>On the first page, I laid out the controls for the first page, and also included a Cancel button, Back button, and Next button.&#160; I really don’t need a Back button for the first page, but i kept it in there as a placeholder and just disabled it by adding a conditional format.&#160; In addition to the fields that the user needs to fill out, we have to perform our own data validation.&#160; The reason is the validation doesn’t fire until the form is submitted, and we need to perform incremental validation just to ensure the first page’s fields are filled out correctly.&#160; I’ll get to the code required to do this shortly, but for now I just added the errorMessage field, set the fill to transparent, removed the border, and disabled it:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image47.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="363" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb45.png" width="660" border="0" /></a> </p>
<p>Next, I created the second page of the wizard by cutting &amp; pasting the first page and adding the appropriate fields:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image48.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="362" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb46.png" width="658" border="0" /></a> </p>
<p>Finally, I created the third page of the wizard, which for this scenario is just a summary page of previously filled-in data:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image49.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="360" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb47.png" width="657" border="0" /></a> </p>
<p>Now that the form UI is set up, we can start adding the rules and code to make it behave like a wizard.&#160; Since I like my code nice and pretty, I renamed all of my buttons to btnCancel1, btnBack1, btnNext1, btnCancel2, etc.&#160; For each cancel button, I added a rule to just close the form.</p>
<p>For the back button, we don’t need to validate the fields, so the code required to jump back to the previous page is straightforward.&#160; To switch views I used the <a href="http://msdn.microsoft.com/en-us/library/aa943181.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">SwitchView()</a> method of the form’s <a href="http://msdn.microsoft.com/en-us/library/aa943181.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">ViewInfoCollection</a>:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">public void </span>btnBack2_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page1&quot;</span>);
}

<span style="color: blue">public void </span>btnBack3_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page2&quot;</span>);
}</pre>
</div>
</p>
</p>
</p>
<p>&#160;</p>
<p>Next I needed to implement the “Next” functionality, but before we switch the view to the next page, the fields on the current page need to be validated.&#160; For this, I added the errorMessage field to each of the pages, and if the validation fails, I set the value of that field to the error message.&#160; To do the validation and to set the field, I created two wrapper methods: GetFieldValue and SetFieldValue:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">private string </span>GetFieldValue(<span style="color: blue">string </span>fieldName)
{
    <span style="color: blue">string </span>xpath = <span style="color: blue">string</span>.Format(<span style="color: maroon">&quot;/my:myFields/my:{0}&quot;</span>, fieldName);
    <span style="color: blue">return </span>MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager).Value;
}

<span style="color: blue">private void </span>SetFieldValue(<span style="color: blue">string </span>fieldName, <span style="color: blue">string </span>value)
{
    <span style="color: blue">string </span>xpath = <span style="color: blue">string</span>.Format(<span style="color: maroon">&quot;/my:myFields/my:{0}&quot;</span>, fieldName);
    MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager).SetValue(value);
}</pre>
</div>
<p>
  <br />Now for the Next buttons, I can verify data has been entered and if not, set the errorMessage field value:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">public void </span>btnNext1_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">if </span>(!<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;firstName&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;lastName&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;emailAddress&quot;</span>)))
    {

        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: blue">string</span>.Empty);
        <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page2&quot;</span>);
    }
    <span style="color: blue">else
    </span>{
        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: maroon">&quot;Please fill out all required information&quot;</span>);
    }
}

<span style="color: blue">public void </span>btnNext2_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">if </span>(!<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;workPhone&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;cellPhone&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;address&quot;</span>)))
    {

        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: blue">string</span>.Empty);
        <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page3&quot;</span>);
    }
    <span style="color: blue">else
    </span>{
        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: maroon">&quot;Please fill out all required information&quot;</span>);
    }
}</pre>
</div>
<p>
  <br />The end result is something like this when an error occurs:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image50.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="497" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb48.png" width="741" border="0" /></a> </p>
<p>
  <br />If all the data has been entered successfully, the last page is eventually visible:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image51.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="497" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb49.png" width="741" border="0" /></a> </p>
<p>&#160;</p>
<p>Pretty slick, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why Isn&#8217;t InfoPath Retrieving All SharePoint List Items?</title>
		<link>http://www.devexpertise.com/2009/02/05/why-isnt-infopath-retrieving-all-sharepoint-list-items/</link>
		<comments>http://www.devexpertise.com/2009/02/05/why-isnt-infopath-retrieving-all-sharepoint-list-items/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 13:59:17 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[InfoPath]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/02/05/why-isnt-infopath-retrieving-all-sharepoint-list-items/</guid>
		<description><![CDATA[InfoPath and SharePoint make a great team when it comes to creating simple electronic forms.&#160; It’s relatively simple to create a robust data-entry form, and is easy to submit an InfoPath form to a form library.&#160; It’s even simple to pull in data that is stored in a SharePoint list.&#160; However, what you may not [...]]]></description>
			<content:encoded><![CDATA[<p>InfoPath and SharePoint make a great team when it comes to creating simple electronic forms.&#160; It’s relatively simple to create a robust data-entry form, and is easy to submit an InfoPath form to a form library.&#160; It’s even simple to pull in data that is stored in a SharePoint list.&#160; However, what you may not realize is if a data connection is configured to retrieve SharePoint list items, it <em>only retrieves the items from the first page of the default view.</em>&#160; What does that mean?&#160; Let’s say you have a SharePoint list that contains 500 items, and your default view (the view that is loaded whenever you visit the list) is set to only show 100 items at a time (like it is by default).&#160; When InfoPath executes its query to retrieve the list items, it will only retrieve 100 items.&#160; More specifically, it will only retrieve the <em>first</em> 100 items.&#160; So, if you happen to change the default view’s criteria or sort order, then InfoPath will be pulling in a different set of data! Don’t believe me? Let’s take a look…</p>
<p>To begin, I created a custom list in SharePoint named Widgets, and added 100 items to it.&#160; Next, I created a new view named Sample View in the list, and set that as the list’s default view:     <br /><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image20.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="139" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb18.png" width="677" border="0" /></a> </p>
<p>Next, I set the Item Limit to only 7 items per page:    <br /><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image21.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="157" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb19.png" width="698" border="0" /></a></p>
<p>After clicking OK and saving the view, whenever I access my list I’m presenting with the first 7 items in the list:    <br /><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image22.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="296" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb20.png" width="748" border="0" /></a> </p>
<p>Now that I have a data source, I create my InfoPath form and set up a data connection to retrieve data from the Widgets list.&#160; I added the results of the data source to a repeating table, and whenever I run my form, I am only presented with the first 7 items (told ya!):    <br /><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image23.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="362" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb21.png" width="577" border="0" /></a> </p>
<p>Just to make sure this is the actual behavior and I’m not just hallucinating after a long day, I modified the view and changed the sort order to sort by Title in descending order, and changed the item limit to display 12 items at a time:    <br /><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image24.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="327" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb22.png" width="697" border="0" /></a>&#160;<a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image25.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="157" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb23.png" width="695" border="0" /></a> </p>
<p>When I open the form again and the data connection is executed, it retrieves the first 12 items after the new sort has been applied!:    <br /><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image26.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="484" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb24.png" width="577" border="0" /></a> </p>
<p>One would think that there would be some type of configuration option in the data connection wizard that asks to retrieve all items, or the results from a specific view, but there isn’t.&#160; If you do need to retrieve all list items, it’s imperative that your list’s default view displays them all, or consider a different data retrieval method such as the built-in or custom web services.</p>
<p>There’s even a KB article that says this behavior is by design: <a href="http://support.microsoft.com/kb/892954" onclick="javascript:pageTracker._trackPageview('/outbound/article/support.microsoft.com');">http://support.microsoft.com/kb/892954</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/02/05/why-isnt-infopath-retrieving-all-sharepoint-list-items/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
