<?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>SharePoint Fun &#187; PeopleEditor</title>
	<atom:link href="http://blog.qumsieh.ca/tag/peopleeditor/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.qumsieh.ca</link>
	<description>Developer's blog related to ASP.NET, SharePoint and Telerik Web Controls</description>
	<lastBuildDate>Tue, 27 Jul 2010 03:07:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Validating a PeopleEditor Control &#8211; Second Attempt</title>
		<link>http://blog.qumsieh.ca/2009/03/05/validating-a-peopleeditor-control-second-attempt/</link>
		<comments>http://blog.qumsieh.ca/2009/03/05/validating-a-peopleeditor-control-second-attempt/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 05:41:14 +0000</pubDate>
		<dc:creator>shereen</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[PeopleEditor]]></category>

		<guid isPermaLink="false">http://blog.qumsieh.ca/?p=383</guid>
		<description><![CDATA[This post is an update to a previous post I had written on validating the PeopleEditor control on post back. In that particular post, I described the challenges of getting a PeopleEditor control, within a custom application page, to validate correctly as a required field on the client side (I had server side validation already [...]]]></description>
			<content:encoded><![CDATA[<p>This post is an update to a <a href="http://blog.qumsieh.ca/2009/02/12/validating-a-peopleeditor-control-on-postback/">previous post</a> I had written on validating the <strong>PeopleEditor</strong> control on post back. In that particular post, I described the challenges of getting a <strong>PeopleEditor</strong> control, within a custom application page, to validate correctly as a required field on the client side (I had server side validation already in place and working correctly).</p>
<p>For the most part, the solution I outlined worked well, except for some situations where other controls on the page were performing their own post back (for example, a data grid in edit mode). I found that on submit of the entire form, the ASP.NET required field validator for the <strong>PeopleEditor</strong> control would kick in informing me that the field was required. However, there was a valid entry in the control so I could only conclude that the post back by some other control on the page was mucking up the view state for the <strong>PeopleEditor</strong> control and on submit the form was no longer aware that this field did in fact have a value in it.</p>
<p>The <strong>MSDN</strong> article found <a href="http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/7ea35995-b907-48a4-8a44-cfbd7b549b2b/">here</a> outlines my problem exactly with the eventual solution further down in the thread. I just wanted to highlight it here because it was exactly what I needed to resolve my issue. Thank you to Jan Lange for posting his solution!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>  
    <span style="color: #003366; font-weight: bold;">function</span> CheckProjectManager<span style="color: #009900;">&#40;</span>source<span style="color: #339933;">,</span> arguments<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>  
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>aspnetForm.<span style="color: #660066;">ctl00_PlaceHolderMain_ProjectManager_downlevelTextBox</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>  
            arguments.<span style="color: #660066;">IsValid</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>  
        <span style="color: #000066; font-weight: bold;">else</span>  
            arguments.<span style="color: #660066;">IsValid</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span>  
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>SharePoint<span style="color: #008000;">:</span>PeopleEditor   
                ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ProjectManager&quot;</span>   
                AllowEmpty<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span>   
                ValidatorEnabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span>   
                MultiSelect<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> 
                runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span>   
                SelectionSet<span style="color: #008000;">=</span><span style="color: #666666;">&quot;User&quot;</span> 
                Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;200px&quot;</span>   
                TabIndex<span style="color: #008000;">=</span><span style="color: #666666;">&quot;2&quot;</span> <span style="color: #008000;">/&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>CustomValidator  
                ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rfvProjectManager&quot;</span> 
                runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> 
                ControlToValidate<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&quot;</span> 
                ErrorMessage<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Required&quot;</span> 
                Enabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span>   
                ClientValidationFunction<span style="color: #008000;">=</span><span style="color: #666666;">&quot;CheckProjectManager&quot;</span><span style="color: #008000;">&gt;</span>  
                <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>CustomValidator<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>Just to outline, what Jan eventually did was create a custom validator that called a javascript function to validate the control. Within that function he checks to see if the control is empty and stores the results of the validation in the <strong>IsValid</strong> property of the <strong>ServerValidateEventArgs</strong> object. Notice that he also sets the <strong>ControlToValidate</strong> property to &#8220;&#8221;.</p>
<p>Hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qumsieh.ca/2009/03/05/validating-a-peopleeditor-control-second-attempt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Performance Considerations With the PeopleEditor Control</title>
		<link>http://blog.qumsieh.ca/2009/02/20/performance-considerations-with-the-peopleeditor-control/</link>
		<comments>http://blog.qumsieh.ca/2009/02/20/performance-considerations-with-the-peopleeditor-control/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 22:02:36 +0000</pubDate>
		<dc:creator>shereen</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[PeopleEditor]]></category>

		<guid isPermaLink="false">http://blog.qumsieh.ca/?p=353</guid>
		<description><![CDATA[I was recently working on a Black Ninja Software project for a client of ours where performance became an issues for one of the custom application pages we had developed. I plan to write up a more detailed report on how I managed to cut the load times of this particular page in half using [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently working on a <a href="http://blackninjasoftware.com">Black Ninja Software</a> project for a client of ours where performance became an issues for one of the custom application pages we had developed. I plan to write up a more detailed report on how I managed to cut the load times of this particular page in half using the <a href="http://www.red-gate.com/Products/ants_profiler/index.htm">ANTS Profiler</a>, but for now I wanted to highlight a piece of the puzzle that I discovered today.</p>
<p>I won&#8217;t cover how to load values into a PeopleEditor control from within a SharePoint list, you can view that in more detail <a href="http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-loading-data-to-a-column-of-type-person-or-group/">here</a>.</p>
<p>Take a look at the example below:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">SPFieldUserValue user <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPFieldUserValue<span style="color: #000000;">&#40;</span>web, Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>listItem<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Employee]));
&nbsp;
peEmployee.CommaSeparatedAccounts = user.LookupValue;</span></pre></td></tr></table></div>

<p>If we have an <strong>SPFieldUserValue</strong> object, calling upon the <strong>LookupValue</strong> property will return the <strong>Name</strong> of that user. This is not to be confused with the <strong>LoginName</strong> property. Assigning that to the <strong>CommaSeparatedAccounts</strong> property may do the trick and will load that user account into the control but not without a performance hit.</p>
<p>A better approach would be:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">SPFieldUserValue user <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPFieldUserValue<span style="color: #000000;">&#40;</span>web, Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>listItem<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Employee&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
peEmployee.<span style="color: #0000FF;">CommaSeparatedAccounts</span> <span style="color: #008000;">=</span> user.<span style="color: #0000FF;">User</span>.<span style="color: #0000FF;">LoginName</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>The difference is minor. Instead of using the <strong>LookupValue</strong> property, we leverage the <strong>SPUser</strong> object and call upon the <strong>LoginName</strong> property. In all of my testing, I noticed an improvement in speed when using the <strong>LoginName</strong> property.</p>
<p>Depending on your environment, the output from either of those properties will differ and that&#8217;s the heart of the performance issues. In my environment, <strong>LoginName</strong> and <strong>Name</strong> outputted the following:</p>
<p>Name &#8211; &#8220;Joe User&#8221;<br />
LoginName &#8211; &#8220;domain\juser&#8221;</p>
<p>Having the domain specified seems to speed this whole process up. I would be interested to hear from anyone else who&#8217;s encountered anything similar.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qumsieh.ca/2009/02/20/performance-considerations-with-the-peopleeditor-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validating a PeopleEditor Control on PostBack</title>
		<link>http://blog.qumsieh.ca/2009/02/12/validating-a-peopleeditor-control-on-postback/</link>
		<comments>http://blog.qumsieh.ca/2009/02/12/validating-a-peopleeditor-control-on-postback/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 18:54:59 +0000</pubDate>
		<dc:creator>shereen</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[PeopleEditor]]></category>

		<guid isPermaLink="false">http://blog.qumsieh.ca/?p=328</guid>
		<description><![CDATA[Let&#8217;s talk about validation and the PeopleEditor control. There doesn&#8217;t seem to be a consensus on how this is supposed to be done so I&#8217;ll outline my findings and what eventually worked for me. I&#8217;ll start by explaining what I was attempting to do. I have a PeopleEditor control on a custom application page. My [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s talk about validation and the <strong>PeopleEditor</strong> control. There doesn&#8217;t seem to be a consensus on how this is supposed to be done so I&#8217;ll outline my findings and what eventually worked for me.</p>
<p>I&#8217;ll start by explaining what I was attempting to do. I have a <strong>PeopleEditor</strong> control on a custom application page. My custom application page is located in the <strong>_layouts</strong> directory. On this page, I also have a submit button that saves my data to a SharePoint list upon submit.</p>
<p>Now, I need to ensure before submit, that the PeopleEditor control contains a valid entry. Blank and invalid values are not permitted.</p>
<p>I first attempted to set the <strong>AlllowEmpty</strong> property to <strong>false</strong>. However, that didn&#8217;t seem to help. If I clicked submit, the page would post back and then the control would display an error once the page reloaded. At this point, it was too late to be informing the user that there was a problem with their entry, the page had already posted back, so this was not useful.</p>
<p>I also tried setting the <strong>ValidationEnabled</strong> property to <strong>true</strong>. That didn&#8217;t seem to make any difference either. I am confused as to how these two properties are supposed to work.</p>
<p>My next attempt was to add an ASP.NET required field validator to the page as follows:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>wssawc<span style="color: #008000;">:</span>PeopleEditor AllowEmpty<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> ValidatorEnabled<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;250px&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;pePR&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> SelectionSet<span style="color: #008000;">=</span><span style="color: #666666;">&quot;User&quot;</span> MultiSelect<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> <span style="color: #008000;">/&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>RequiredFieldValidator ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rfvPR&quot;</span> ControlToValidate<span style="color: #008000;">=</span><span style="color: #666666;">&quot;pePR&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ErrorMessage<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Project Requestor (Cannot be blank)&quot;</span> Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Cannot be blank.&quot;</span> ValidationGroup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SubmitForm&quot;</span> Display<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Dynamic&quot;</span><span style="color: #008000;">&gt;&lt;/</span>asp<span style="color: #008000;">:</span>RequiredFieldValidator<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>This took care of the client side validation that prevented the user from clicking submit without first entering a value into the control.</p>
<p>However, this did not handle the scenario when a user entered an invalid value in the control and hit submit. In this case, the form will attempt to submit and create the item, but will fail to save the value to the list item field because the value was invalid. An example of an invalid value would be bad data in that field.</p>
<p>To fix this, in my submit method, I added an <strong>IF</strong> statement to check how many resolved entities there were.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>pePR.<span style="color: #0000FF;">ResolvedEntities</span>.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// continue with the submit</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// output an error that the user did not enter a valid user</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>If anyone has any feedback, or has had success using the <strong>AllowEmpty</strong> property, please comment on this post or drop me a note. I&#8217;m interested in hearing how others were able to get around this issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qumsieh.ca/2009/02/12/validating-a-peopleeditor-control-on-postback/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Use the PeopleEditor Control: Saving Data</title>
		<link>http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-inside-sharepoint/</link>
		<comments>http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-inside-sharepoint/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 01:50:45 +0000</pubDate>
		<dc:creator>shereen</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[PeopleEditor]]></category>

		<guid isPermaLink="false">http://blog.qumsieh.ca/?p=134</guid>
		<description><![CDATA[The PeopleEditor control is a common control that you&#8217;ll find implemented throughout SharePoint. If you&#8217;re building any custom web parts or application pages, you may want users to enter people specific information. The PeopleEditor is a good choice, however, there isn&#8217;t much out there in terms of documenting it&#8217;s use. Hopefully the information below will [...]]]></description>
			<content:encoded><![CDATA[<p>The PeopleEditor control is a common control that you&#8217;ll find implemented throughout SharePoint. If you&#8217;re building any custom web parts or application pages, you may want users to enter people specific information. The PeopleEditor is a good choice, however, there isn&#8217;t much out there in terms of documenting it&#8217;s use. Hopefully the information below will help get you started. If you are having issues, or if there is something I&#8217;ve missed in my post, please feel free to leave me a comment.</p>
<p>NOTE: One thing I found was that in order for this control to successfully save a user, that user has to exist within the site collection. If they don&#8217;t exist, the web.SiteUsers call will fail with an exception &#8216;user cannot be found&#8217;.</p>
<p><strong>UPDATE</strong>: You can use the <strong>EnsureUser</strong> method to verify that the specified user exists  and is a valid user of the web site. The neat thing about this method is that it will add the user to the site if they do not already exist, thus making the <strong>SiteUsers</strong> call unnecessary. Keep in mind that if you do use this method, you may need to elevate permissions to make that call, as not all users have access to add other users to your site collection.</p>
<p>To get started, create a new <strong>Custom List</strong> named <strong>Demo</strong>. Within <strong>List Settings</strong>, create a column of type <strong>Person or Group</strong> named <strong>Managers</strong>.</p>
<p>In this particular example, I&#8217;ll be building a custom application page with a single PeopleEditor control and a submit button. Create a new page (or download the files I&#8217;ve prepared for this article <a href='http://blog.qumsieh.ca/wp-content/uploads/2008/12/peopleeditor.zip'>here</a>), called <strong>Demo.aspx</strong> and store it in the <strong>_layouts</strong> directory.</p>
<p>Since the people editor control is located within the <strong>Microsoft.SharePoint.WebControls</strong> namespace, you&#8217;ll have to register the tag prefix at the top of your page:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Register TagPrefix<span style="color: #008000;">=</span><span style="color: #666666;">&quot;wssawc&quot;</span> <span style="color: #0600FF;">Namespace</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Microsoft.SharePoint.WebControls&quot;</span> Assembly<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot;</span> <span style="color: #008000;">%&gt;</span></pre></td></tr></table></div>

<p>Insert the control on the page. If you look at my <strong>Demo.aspx</strong> page, I&#8217;ve put my control within a table tag, but you can format this however you&#8217;d like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>wssawc<span style="color: #008000;">:</span>PeopleEditor AllowEmpty<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;300px&quot;</span> id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;peManagers&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> SelectionSet<span style="color: #008000;">=</span><span style="color: #666666;">&quot;User&quot;</span> <span style="color: #008000;">/&gt;</span></pre></td></tr></table></div>

<p><strong>AllowEmtpy</strong> &#8211; let&#8217;s you specify if blank values are permitted for this control<br />
<strong>SelectionSet</strong> &#8211; can be User or SecGroup or SPGroup or all three: User, SecGroup, SPGroup<br />
<strong>MultiSelect</strong> &#8211; set to true or false, false if you don&#8217;t want the user to be able to select more than one</p>
<p>Insert an <strong>asp:Button</strong> control onto the page; we&#8217;ll use this to submit the people data to the list.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Button ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;btnSubmit&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> OnClick<span style="color: #008000;">=</span><span style="color: #666666;">&quot;btnSubmit_Click&quot;</span> ValidationGroup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Main&quot;</span> Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;OK&quot;</span> CssClass<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ms-ButtonHeightWidth&quot;</span> <span style="color: #008000;">/&gt;</span></pre></td></tr></table></div>

<p>In order to save values from the control to the column we created, you&#8217;ll need the following code in the button submit event:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> btnSubmit_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// create a web object with context for the current site</span>
&nbsp;
    SPWeb web <span style="color: #008000;">=</span> SPContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Web</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// get the entries that were entered into the people editor and store them in a string</span>
&nbsp;
    <span style="color: #FF0000;">string</span> managers <span style="color: #008000;">=</span> peManagers.<span style="color: #0000FF;">CommaSeparatedAccounts</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// commaseparatedaccounts returns entries that are comma separated. we want to split those up</span>
&nbsp;
    <span style="color: #FF0000;">char</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> splitter <span style="color: #008000;">=</span> <span style="color: #000000;">&#123;</span> <span style="color: #666666;">','</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> splitPPData <span style="color: #008000;">=</span> managers.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span>splitter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// this collection will store the user values from the people editor which we'll eventually use</span>
    <span style="color: #008080; font-style: italic;">// to populate the field in the list</span>
&nbsp;
    SPFieldUserValueCollection values <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPFieldUserValueCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// for each item in our array, create a new sp user object given the loginname and add to our collection</span>
&nbsp;
    <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> splitPPData.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #FF0000;">string</span> loginName <span style="color: #008000;">=</span> splitPPData<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>loginName<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            SPUser user <span style="color: #008000;">=</span> web.<span style="color: #0000FF;">SiteUsers</span><span style="color: #000000;">&#91;</span>loginName<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// you could also use SPUser user = web.EnsureUser(loginName);</span>
&nbsp;
            SPFieldUserValue fuv <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPFieldUserValue<span style="color: #000000;">&#40;</span>web, user.<span style="color: #0000FF;">ID</span>, user.<span style="color: #0000FF;">LoginName</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            values.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>fuv<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// set the Person or Group column</span>
&nbsp;
    SPListItemCollection listItems <span style="color: #008000;">=</span> web.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Demo&quot;</span><span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Items</span><span style="color: #008000;">;</span>
&nbsp;
    SPListItem manager <span style="color: #008000;">=</span> listItems.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    manager<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Managers&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> values<span style="color: #008000;">;</span>
&nbsp;
    manager.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>That should do it. You should be able to save the entries to the list. If you&#8217;d like to learn how to read values from a list column into a PeopleEditor control, you can read that post <a href="http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-loading-data-to-a-column-of-type-person-or-group/">here</a>. Any feedback?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-inside-sharepoint/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Use the PeopleEditor Control: Loading Data</title>
		<link>http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-loading-data-to-a-column-of-type-person-or-group/</link>
		<comments>http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-loading-data-to-a-column-of-type-person-or-group/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 01:39:35 +0000</pubDate>
		<dc:creator>shereen</dc:creator>
				<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[PeopleEditor]]></category>

		<guid isPermaLink="false">http://blog.qumsieh.ca/?p=116</guid>
		<description><![CDATA[This post was really planned as a Part 2 to the first post I made about saving data from the PeopleEditor control. My aim for this entry is to tackle the reverse scenario: reading data from a field of type Person or Group and loading it into a PeopleEditor control. If you have any troubles [...]]]></description>
			<content:encoded><![CDATA[<p>This post was really planned as a <strong>Part 2</strong> to the first post I made about saving data from the PeopleEditor control. My aim for this entry is to tackle the reverse scenario: reading data from a field of type <strong>Person or Group</strong> and loading it into a PeopleEditor control. If you have any troubles with Part 1 or Part 2 of this series or if there&#8217;s something I&#8217;ve missed, I would love to hear about it. Leave a comment or drop me an email. Thanks!</p>
<p>If you&#8217;ve followed <a href="http://blog.qumsieh.ca/2008/7/21/how-to-use-the-people-editor-control-inside-sharepoint">Part 1</a> of this series, you should already have a list named <strong>Demo</strong> created with a column of type <strong>Person or Group</strong> named <strong>Managers</strong>. If not, begin by creating a new <strong>Custom List</strong> named <strong>Demo</strong>. Within <strong>List Settings</strong>, create a column of type <strong>Person or Group</strong> and name it <strong>Managers</strong>. Set the <strong>Allow multiple selections</strong> checkbox to <strong>Yes</strong>.</p>
<p>Once you&#8217;ve created the list and the column, add a few new entries so we have some data to load.</p>
<p>Now let&#8217;s create a custom application page with a single PeopleEditor control on it. Create a new page (or download it <a href='http://blog.qumsieh.ca/wp-content/uploads/2008/12/peopleeditorload.zip'>here</a>) called Load.aspx and store it in the layouts directory.</p>
<p>Since the people editor control is located within the <strong>Microsoft.SharePoint.WebControls</strong> namespace, you&#8217;ll have to register the tag prefix at the top of your page:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Register TagPrefix<span style="color: #008000;">=</span><span style="color: #666666;">&quot;wssawc&quot;</span> <span style="color: #0600FF;">Namespace</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;Microsoft.SharePoint.WebControls&quot;</span> Assembly<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot;</span> <span style="color: #008000;">%&gt;</span></pre></td></tr></table></div>

<p>Insert the control on the page. This is the control we&#8217;ll be loading the data into:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>wssawc<span style="color: #008000;">:</span>PeopleEditor AllowEmpty<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> Width<span style="color: #008000;">=</span><span style="color: #666666;">&quot;300px&quot;</span> id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Managers&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> SelectionSet<span style="color: #008000;">=</span><span style="color: #666666;">&quot;User&quot;</span> <span style="color: #008000;">/&gt;</span></pre></td></tr></table></div>

<p>The next step will require that we wire up our <strong>Page_Load</strong> event to load the necessary data from the list to the control.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">try</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
        SPWeb web <span style="color: #008000;">=</span> SPContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Web</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// get a handle to the list weâ€™ll be pulling values from</span>
        SPList list <span style="color: #008000;">=</span> web.<span style="color: #0000FF;">Lists</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Demo&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// using the querystring parameter containing the id, get the list item weâ€™ll be dealing with</span>
        SPListItem listItem <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">GetItemById</span><span style="color: #000000;">&#40;</span>Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>Request<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;id&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// the managers column is of type Person or Group, so we can use a spfielduservaluecollection to     store the values from it</span>
        SPFieldUserValueCollection users <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>SPFieldUserValueCollection<span style="color: #000000;">&#41;</span>listItem<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Managers&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// our array will hold the entities weâ€™ll use to eventually assign to the people editor control</span>
        ArrayList entityArrayList <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ArrayList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// loop through each use in the collection, set the key, add to the array</span>
        <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> users.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            PickerEntity entity <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PickerEntity<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            entity.<span style="color: #0000FF;">Key</span> <span style="color: #008000;">=</span> users<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">User</span>.<span style="color: #0000FF;">LoginName</span><span style="color: #008000;">;</span>
            entityArrayList.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>entity<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        Managers.<span style="color: #0000FF;">UpdateEntities</span><span style="color: #000000;">&#40;</span>entityArrayList<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
&nbsp;
        Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>ex.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Now when you navigate to your page, pass the id of a valid item in the list, and the entries in the manager column should load: http://servername/_layouts/Load.aspx?id=1 (replace servername with the name of your MOSS install)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.qumsieh.ca/2008/07/21/how-to-use-the-people-editor-control-loading-data-to-a-column-of-type-person-or-group/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
