<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><!--RSS generated by Windows SharePoint Services V3 RSS Generator on 11/9/2009 2:29:25 AM--><rss version="2.0">
  <channel>
    <title>Weblog Ton Stegeman [MVP]: Posts</title>
    <link>http://www.tonstegeman.com/Blog/Lists/Posts/AllPosts.aspx</link>
    <description>RSS feed for the Posts list.</description>
    <lastBuildDate>Mon, 09 Nov 2009 10:29:25 GMT</lastBuildDate>
    <generator>Windows SharePoint Services V3 RSS Generator</generator>
    <ttl>60</ttl>
    <image>
      <title>Weblog Ton Stegeman [MVP]: Posts</title>
      <url>/Blog/_layouts/images/homepage.gif</url>
      <link>http://www.tonstegeman.com/Blog/Lists/Posts/AllPosts.aspx</link>
    </image>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/tonstegeman" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>New version of Content by Type and filter web parts and a new family member</title>
      <link>http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=119</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass260C5403C58542FFBA9A61798AB41A93><p>On my <a href="http://sharepointobjects.codeplex.com" target="_blank">CodePlex project</a> I have just released a new version of the <strong>Content By Type</strong> web part and the <strong>Filter webparts</strong>. This post will summarize the changes in the web parts. It will also introduce the latest family member, the <strong>User Information Filter</strong> web part. I have introduced the Content By Type web parts two years ago, and some time later I introduced the filter web parts to the package. Currently the web part package has been downloaded nearly 3000 times and I get some great feedback en feature requests. So it was time for a new version. I want to thank <strong>Jesus Lopez</strong> from Spain for creating a number of nice new features. Thank you very much!</p> <h3>User Info Filter Web Part</h3> <p>This web part is new in this release of the package. It can get a value from the User Information List from the current user and pass that as a filter value to connected web parts. The screenshot below shows an example. It shows the page in edit mode. The User Info Filter web part is a context filter web part and therefore is not visible at runtime. In this example, it is used twice. The upper web part gets and name of the logged on user and passes that to the connected <em>My News</em> web part. This is a Content By Type web part that queries the site collection for news items published by myself. The second User Info Filter gets the department for the current user and passes that to the <em>My department news</em> web part. This shows an overview of all news published by my department.</p> <p><a href="/blog/Lists/Posts/Attachments/119/image_2_4C87EA6E.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_4C87EA6E.png" width=543 height=530></a> </p> <p>This new filter web part is available both in WSS and MOSS. Besides being a filter provider, the <strong>User Info Filter </strong>web part also is a filter consumer. This way you can load properties of another user from the User Information List in SharePoint. Another filter web part on the page provides the name (or any other user property) to the User Info Filter. This web part finds that user in the User Information list and passes one of the values of that user to the consumers. The screenshot below shows an example.</p> <p><a href="/blog/Lists/Posts/Attachments/119/image_4_4C87EA6E.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_1_7A753D26.png" width=534 height=491></a> </p> <p>In this screenshot you see a <strong>List Item Filter</strong> web part. This lets users pick an author from a list. The name of this author is passed as filter value to a <strong>User Info Filter</strong> web part and a <strong>Content By Type</strong> web part. The user info filter web part load the department for the selected user and sends that value to another <strong>Content By Type</strong> web part. These two news web parts aggregate the news written by that user, or written by the department of that user.</p> <h3>Content By Type web part</h3> <p>This paragraph shows all new features of release 1.3 of the Content By Type web part:</p> <ol> <li>Filter using column headers<br>Just like any List View web part in SharePoint, you can now filter the Content By Type content by selecting one of the values in one of the column headers.<br><a href="/blog/Lists/Posts/Attachments/119/image_16_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_7_7A753D26.png" width=602 height=291></a> </li> <li>If you use grouping, you now have an option to hide the fieldname from the group header.<br><a href="/blog/Lists/Posts/Attachments/119/image_18_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_8_7A753D26.png" width=406 height=55></a> </li> <li>The context menu can show the option to take users directly to the folder that contains the item / document. Instead of redirecting you to the list and making you find the folder yourself, the web part now directly redirects you to the folder.<br><a href="/blog/Lists/Posts/Attachments/119/image_14_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_6_7A753D26.png" width=188 height=101></a> </li> <li>While configuring the web part, you decide what options appear in the context menu. Instead of all options, you can select what options will be available for your users.<br><a href="/blog/Lists/Posts/Attachments/119/image_12_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_5_7A753D26.png" width=405 height=97></a> </li> <li>Links to display and edit forms now pass the current page as <em>Source</em> parameter in the querystring. Users are redirected back to your overview page when they click the <em>Close</em> button.</li> <li>There is a new option to collapse all groups by default.<br><a href="/blog/Lists/Posts/Attachments/119/image_8_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_3_7A753D26.png" width=382 height=42></a>  </li> <li>An item in the list can now be linked directly to either the item, the folder, the list or the site. In previous versions you could only link to the item directly.<br><a href="/blog/Lists/Posts/Attachments/119/image_6_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_2_7A753D26.png" width=393 height=155></a> </li></ol> <h3>Item Filter web part</h3> <p>There have been a number of enhancements to the list item filter web part:</p> <ol> <li>Improvements have been made to the loading mechanism of the list. You enter the server relative url to the site and the list. You can use the <strong>title</strong> of the list, or the <strong>url name</strong>. If you want to use a list from the current site, simply enter the title or url name of the list, without any slashes. In WSS the guidance to enter the reference to the list is improved.</li> <li>The tag cloud has the option to display a ´Show all´ link. This link can be used to reset a previously selected filter.<br><a href="/blog/Lists/Posts/Attachments/119/image_20_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_9_7A753D26.png" width=189 height=39></a> </li> <li>You can now use multiple webparts that show a tag cloud on the same page. They no longer interfere with each other.</li> <li>While configuring the web part, you can now set an item limit for the query.<br><a href="/blog/Lists/Posts/Attachments/119/image_24_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_11_7A753D26.png" width=175 height=50></a> </li> <li>If you are using multiple List Item filter web parts on the same page that use the <em>Checkbox</em> display mode, you can hide the search button for all but one.<br><a href="/blog/Lists/Posts/Attachments/119/image_22_7A753D26.png"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title=image border=0 alt=image src="/blog/Lists/Posts/Attachments/119/image_thumb_10_7A753D26.png" width=161 height=118></a> </li> <li>Items in sub folders are now also included in the filter web part.</li> <li>There has been a bug fix in connecting to and from the web part when used in the Tag Cloud display mode.</li> <li>Loading a list from a site collection that is using an ´explicit inclusion´ managed path now works.</li></ol> <h3>Page Column Filter web part</h3> <p>This release of the Page Column Filter web part has a number of improvements:</p> <ol> <li>The reference to the selected field is stored in the web part configuration as the internal name of the field, instead of the ID. This makes it easier to use the web part in multi server environments (like developement, test, production)</li> <li>The web part can now be used in a page layout directly.</li> <li>The web part now also sends values of calculated fields to connected web parts.</li></ol> <h3>Web Context Filter web part</h3> <ol> <li>Release 1.3 of the filter web parts makes the Web Context Filter web part available in WSS. Previous versions could only be used in MOSS.</li> <li>The web part can now be used in a page layout directly.</li></ol> <p>The new package is released as version 1.3 on <a href="http://sharepointobjects.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=35487" target="_blank">this CodePlex page</a>. Enjoy the new version!</p></div></div>
<div><b>Published:</b> 11/5/2009 1:14 PM</div>
<div><b>Attachments:</b> <a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_12_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_12_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_14_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_14_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_16_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_16_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_18_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_18_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_2_4C87EA6E.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_2_4C87EA6E.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_20_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_20_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_22_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_22_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_24_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_24_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_4_4C87EA6E.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_4_4C87EA6E.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_6_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_6_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_8_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_8_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_1_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_1_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_10_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_10_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_11_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_11_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_2_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_2_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_3_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_3_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_4C87EA6E.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_4C87EA6E.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_5_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_5_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_6_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_6_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_7_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_7_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_8_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_8_7A753D26.png</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_9_7A753D26.png">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/119/image_thumb_9_7A753D26.png</a><br><a href=""></a></div>
]]></description>
      <author>Ton Stegeman</author>
      <pubDate>Thu, 05 Nov 2009 21:14:37 GMT</pubDate>
      <guid isPermaLink="true">http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=119</guid>
    </item>
    <item>
      <title>SharePoint 2010 Client Object Models – The ECMAScript library</title>
      <link>http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=118</link>
      <description><![CDATA[<div><b>Body:</b> <div class=ExternalClass5179134122D546A6AB55303F85D3E1E9><p>As you probably have seen/heard in the news on last week’s SharePoint Conference in Las Vegas, SharePoint 2010 will ship with 3 new object models:</p> <ul> <li>a managed .NET API for building client applications using a SharePoint object model.  <li>a managed Silverlight object model.  <li>an object model to be used in Javascript, the ECMAScript library.</li></ul> <p>For developers this is an important step forward. Until now, developing SharePoint applications using an object model was limited to applications running on the server. For client applications we had to rely on web services and the RPC protocols. Using these 3 new models, it will be much easier to create client applications. And the reach of our applications will be bigger, because they are very likely to also run on the new SharePoint Online. The three object models are a limited sub set of the server object model. Most objects, properties and methods of the site collection (SPSite) and it’s underlying structures are available in the new models. </p> <p>In this article I will show you an example of a custom ASPX page that will use the Javascript library. It is a page that runs in the LAYOUTS folder. It shows all users that have direct permissions on the current site. By clicking a user name, the page will show me more information about that user. By selecting a user and one of the available SharePoint groups, the page will add the user to that group. After doing that, the page will remove the permissions for the user. The screenshot below shows the page:</p> <p><a href="/blog/Lists/Posts/Attachments/118/ClientObjectModelsFiguur3_2_12FC64E0.jpg"><img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px" title="Client Object Models - Figuur 3" border=0 alt="Client Object Models - Figuur 3" src="/blog/Lists/Posts/Attachments/118/ClientObjectModelsFiguur3_thumb_12FC64E0.jpg" width=779 height=293></a> </p> <p>Showing the users and the user groups is done in server side code. Showing user information and moving the user’s permissions to the group is handled by javascript using the ECMAScript library.</p> <p><strong>Step 1 – Show the users and groups</strong></p> <p>The ASPX page loads the lists with users and groups in the <em>OnLoad</em> of the page. It creates a collection of custom objects and sets these collections as the datasource for the <em>Repeater</em> controls. The code snippet below shows how the users are loaded:</p> <div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 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:'Courier New', courier, monospace;direction:ltr;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px" id=codeSnippetWrapper> <div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px" id=codeSnippet><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum1>   1:</span> SPWeb web = SPContext.Current.Web;</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum2>   2:</span> List&lt;SharePointUser&gt; users = <span style="color:#0000ff">new</span> List&lt;SharePointUser&gt;();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum3>   3:</span> <span style="color:#0000ff">foreach</span> (SPRoleAssignment assignment <span style="color:#0000ff">in</span> web.RoleAssignments)</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum4>   4:</span> {</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum5>   5:</span>     <span style="color:#0000ff">if</span> (assignment.Member <span style="color:#0000ff">is</span> SPUser)</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum6>   6:</span>     {</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum7>   7:</span>         SPUser user = (SPUser)assignment.Member;</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum8>   8:</span>         SharePointUser usr = <span style="color:#0000ff">new</span> SharePointUser(user.ID, user.Name);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum9>   9:</span>         users.Add(usr);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum10>  10:</span>     }</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum11>  11:</span> }</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum12>  12:</span> listUsers.DataSource = users;</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum13>  13:</span> listUsers.DataBind();</pre></div></div>
<p>The snippet below shows the ASPX code for the repeater that shows the users:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 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:'Courier New', courier, monospace;direction:ltr;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px" id=codeSnippetWrapper>
<div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px" id=codeSnippet><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum1>   1:</span> <span style="color:#0000ff">&lt;</span><span style="color:#800000">asp:Repeater</span> <span style="color:#ff0000">ID</span><span style="color:#0000ff">=&quot;listUsers&quot;</span> <span style="color:#ff0000">runat</span><span style="color:#0000ff">=&quot;server&quot;</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum2>   2:</span>     <span style="color:#0000ff">&lt;</span><span style="color:#800000">HeaderTemplate</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum3>   3:</span>     <span style="color:#0000ff">&lt;</span><span style="color:#800000">h3</span><span style="color:#0000ff">&gt;</span>Users with direct permissions on this site<span style="color:#0000ff">&lt;/</span><span style="color:#800000">h3</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum4>   4:</span>     <span style="color:#0000ff">&lt;/</span><span style="color:#800000">HeaderTemplate</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum5>   5:</span>     <span style="color:#0000ff">&lt;</span><span style="color:#800000">ItemTemplate</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum6>   6:</span>     <span style="color:#0000ff">&lt;</span><span style="color:#800000">li</span> <span style="color:#ff0000">style</span><span style="color:#0000ff">=&quot;list-style-type:none&quot;</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum7>   7:</span>         <span style="color:#0000ff">&lt;</span><span style="color:#800000">input</span> <span style="color:#ff0000">type</span><span style="color:#0000ff">=&quot;checkbox&quot;</span> <span style="color:#ff0000">id</span><span style="color:#0000ff">=&quot;selectUser&lt;%# DataBinder.Eval(Container.DataItem, &quot;</span><span style="color:#ff0000">ID</span><span style="color:#0000ff">&quot;) %&gt;&quot;</span> <span style="color:#ff0000">name</span><span style="color:#0000ff">=&quot;selectUser&quot;</span> <span style="color:#0000ff">/&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum8>   8:</span>         <span style="color:#0000ff">&lt;</span><span style="color:#800000">a</span> <span style="color:#ff0000">href</span><span style="color:#0000ff">=&quot;javascript:getUserInfo(&lt;%# DataBinder.Eval(Container.DataItem, &quot;</span><span style="color:#ff0000">ID</span><span style="color:#0000ff">&quot;) %&gt;);&quot;</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum9>   9:</span>             <span style="color:#0000ff">&lt;</span> %# DataBinder.Eval(Container.DataItem, &quot;Name&quot;) <span style="background-color:#ffff00">%&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum10>  10:</span>         <span style="color:#0000ff">&lt;/</span><span style="color:#800000">a</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum11>  11:</span>     <span style="color:#0000ff">&lt;/</span><span style="color:#800000">li</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum12>  12:</span>     <span style="color:#0000ff">&lt;/</span><span style="color:#800000">ItemTemplate</span><span style="color:#0000ff">&gt;</span></pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum13>  13:</span> <span style="color:#0000ff">&lt;/</span><span style="color:#800000">asp:Repeater</span><span style="color:#0000ff">&gt;</span></pre></div></div>
<p>For every user in the collection, a hyperlink is rendered. When the link is clicked, javascript function “<em>selectUser</em>” is called. This function takes the ID of the user as parameter</p>
<p><strong>Step 2 – Preparing the page for using the ECMAScript library</strong></p>
<p>The ECMAScript library is available in a number of JS files in the LAYOUTS folder. The main file is <em>SP.js</em>. When you include this file in the APSX page using a <em>ScriptLink</em> control, all other required JS files are loaded automatically. This <a href="http://msdn.microsoft.com/en-us/library/ee539757(office.14).aspx" target="_blank">MSDN page</a> shows all relevant files. By linking <em>SP.js</em> to your page, the <strong><em>SP</em></strong> namespace is registered. This is the SharePoint namespace that contains all objects. If you are going to build code using this library, you will very likely need <a href="http://msdn.microsoft.com/en-us/library/ee557057(office.14).aspx" target="_blank">this MSDN Page</a> to reference what object, properties and methods are available. The SharePoint js files are minified (‘crunched’ in the SDK) versions. This makes them hard to read and use for debugging. Therefore every js file also has a ‘debug’ equivalent in the same folder. By opening <em>sp.debug.js</em> you will be able to see what is available in the SP namespace. </p>
<p>The snippet below show how to prepare the ASPX page:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 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:'Courier New', courier, monospace;direction:ltr;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px" id=codeSnippetWrapper>
<div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px" id=codeSnippet><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum1>   1:</span> <span style="color:#0000ff">&lt;</span><span style="color:#800000">SharePoint:ScriptLink</span> </pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum2>   2:</span>     <span style="color:#ff0000">Name</span><span style="color:#0000ff">=&quot;sp.js&quot;</span> <span style="color:#ff0000">LoadAfterUI</span><span style="color:#0000ff">=&quot;true&quot;</span> <span style="color:#ff0000">Localizable</span><span style="color:#0000ff">=&quot;false&quot;</span> </pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum3>   3:</span>     <span style="color:#ff0000">runat</span><span style="color:#0000ff">=&quot;server&quot;</span> <span style="color:#ff0000">ID</span><span style="color:#0000ff">=&quot;ScriptLink1&quot;</span> <span style="color:#0000ff">/&gt;</span></pre></div></div>
<p><strong>Step 3 – Getting the user information</strong></p>
<p>As we have seen in step 1, clicking a user’s name fires the javascript function ‘<em>selectUser</em>’. This function is shown in the snippet below. </p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 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:'Courier New', courier, monospace;direction:ltr;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px" id=codeSnippetWrapper>
<div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px" id=codeSnippet><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum1>   1:</span> <span style="color:#0000ff">function</span> getUserInfo(userID) {</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum2>   2:</span>     <span style="color:#0000ff">var</span> clientContext = <span style="color:#0000ff">new</span> SP.ClientContext.get_current();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum3>   3:</span>     <span style="color:#0000ff">var</span> web = clientContext.get_web();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum4>   4:</span>     <span style="color:#0000ff">var</span> userInfoList = web.get_siteUserInfoList();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum5>   5:</span>     <span style="color:#0000ff">var</span> camlQuery = <span style="color:#0000ff">new</span> SP.CamlQuery();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum6>   6:</span>     camlQuery.set_viewXml(<span style="color:#006080">'&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=\'ID\'/&gt;'</span> +</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum7>   7:</span>                           <span style="color:#006080">'&lt;Value Type=\'Number\'&gt;'</span> + userID + <span style="color:#006080">'&lt;/Value&gt;&lt;/Eq&gt;'</span> +</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum8>   8:</span>                           <span style="color:#006080">'&lt;/Where&gt;&lt;/Query&gt;&lt;RowLimit&gt;1&lt;/RowLimit&gt;&lt;/View&gt;'</span>);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum9>   9:</span>     <span style="color:#0000ff">this</span>.collListItem = userInfoList.getItems(camlQuery);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum10>  10:</span>     clientContext.load(collListItem);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum11>  11:</span>     clientContext.executeQuery(</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum12>  12:</span>         Function.createDelegate(<span style="color:#0000ff">this</span>, <span style="color:#0000ff">this</span>.onQuerySucceeded), </pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum13>  13:</span>         Function.createDelegate(<span style="color:#0000ff">this</span>, <span style="color:#0000ff">this</span>.onQueryFailed));</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum14>  14:</span> }</pre></div></div>
<p>As in server side code, we first need to get the SharePoint context. Because our page is an ASPX page running in the LAYOUTS folder, it is always in context of the current SharePoint site. In all 3 new client object models, the SharePoint context is represented in a <em>ClientContext</em> object. In line 2 of the snippet above, we’re getting the current SharePoint context. The next few lines look pretty familiar if you are used to SharePoint server side programming. We are getting a reference to the User Information List of the current site. Next we create a CAML query to find the list item for the user that was selected, and we load the items based on that query from the list. The big difference with the server side object model, is that we did not yet have any contact with SharePoint. Although we have called the <em>getItems</em> method of the list, our collection is not yet loaded. This happens when we load the collection in line 10 and execute the query using <em><strong>clientContext.ExecuteQuery</strong></em> in line 11. This gives you the option to minimize the number of roundtrips to the server from your client code. This makes SharePoint client programming different from server side programming. You need to do more thinking about what objects and properties to use when. It makes sense to load as many objects you need, before calling ExecuteQuery once, to actually get the objects from the server.</p>
<p>In the sample above, you see another difference between client and server side programming. The ECMAScript library is, as the Silverlight API, asynchronous. The ExecuteQuery method takes 2 parameter, the functions that will be called in both a success and a failure scenario. The snippet below shows the ´success´ function of my sample page:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 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:'Courier New', courier, monospace;direction:ltr;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px" id=codeSnippetWrapper>
<div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px" id=codeSnippet><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum1>   1:</span> <span style="color:#0000ff">function</span> onQuerySucceeded(sender, args) {</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum2>   2:</span>     <span style="color:#0000ff">var</span> item = collListItem.itemAt(0);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum3>   3:</span>     <span style="color:#0000ff">var</span> profile = item.get_item(<span style="color:#006080">'Notes'</span>);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum4>   4:</span>     <span style="color:#0000ff">var</span> pictureUrl = item.get_item(<span style="color:#006080">'Picture'</span>).get_url();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum5>   5:</span>     </pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum6>   6:</span>     <span style="color:#0000ff">var</span> userImage = document.getElementById(<span style="color:#006080">'userImage'</span>);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum7>   7:</span>     userImage.src = pictureUrl;</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum8>   8:</span>     <span style="color:#0000ff">var</span> profileDiv = document.getElementById(<span style="color:#006080">'userProfile'</span>);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum9>   9:</span>     profileDiv.innerHTML = profile;</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum10>  10:</span> }</pre></div></div>
<p>This code loads the first item from the collection, get the values of the Notes and Picture</p>
<p><strong>Step 4 – Move the user to the group</strong></p>
<p>Last part of this article show how to remove the user permissions and add the user to the selected group. When a groupname is clicked, the javascript function <em>moveSelectedUsersToGroup</em> is called and the ID of the group is passed as parameter. The snippet below shows this function:</p>
<div style="border-bottom:silver 1px solid;text-align:left;border-left:silver 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:'Courier New', courier, monospace;direction:ltr;font-size:8pt;overflow:auto;border-top:silver 1px solid;cursor:text;border-right:silver 1px solid;padding-top:4px" id=codeSnippetWrapper>
<div style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px" id=codeSnippet><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum1>   1:</span> <span style="color:#0000ff">function</span> moveSelectedUsersToGroup(groupID) {</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum2>   2:</span>     <span style="color:#0000ff">var</span> users = document.getElementsByName(<span style="color:#006080">'selectUser'</span>);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum3>   3:</span>     <span style="color:#0000ff">this</span>.clientContext = <span style="color:#0000ff">new</span> SP.ClientContext.get_current();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum4>   4:</span>     <span style="color:#0000ff">this</span>.web = clientContext.get_web();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum5>   5:</span>     <span style="color:#0000ff">var</span> groups = web.get_siteGroups();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum6>   6:</span>     <span style="color:#0000ff">var</span> group = groups.getById(groupID);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum7>   7:</span>     <span style="color:#0000ff">var</span> groupUsers = group.get_users();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum8>   8:</span>     <span style="color:#0000ff">for</span> (i = 0; i &lt; users.length; i++) {</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum9>   9:</span>         <span style="color:#0000ff">if</span> (users[i].<span style="color:#0000ff">checked</span>) {</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum10>  10:</span>             <span style="color:#0000ff">var</span> id = users[i].id.replace(/selectUser/, <span style="color:#006080">''</span>);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum11>  11:</span>             <span style="color:#0000ff">var</span> siteUsers = web.get_siteUsers();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum12>  12:</span>             <span style="color:#0000ff">var</span> user = siteUsers.getById(id);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum13>  13:</span>             groupUsers.addUser(user);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum14>  14:</span>             <span style="color:#0000ff">var</span> assignments = web.get_roleAssignments();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum15>  15:</span>             <span style="color:#0000ff">var</span> assignment = assignments.getByPrincipalId(id);</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum16>  16:</span>             assignment.deleteObject();</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum17>  17:</span>             clientContext.executeQuery(</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum18>  18:</span>                 Function.createDelegate(<span style="color:#0000ff">this</span>, <span style="color:#0000ff">this</span>.addUsersSucceeded), </pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum19>  19:</span>                 Function.createDelegate(<span style="color:#0000ff">this</span>, <span style="color:#0000ff">this</span>.onQueryFailed));</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum20>  20:</span>         }</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:white;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum21>  21:</span>     }</pre><pre style="border-bottom-style:none;text-align:left;padding-bottom:0px;line-height:12pt;border-right-style:none;background-color:#f4f4f4;margin:0em;padding-left:0px;width:100%;padding-right:0px;font-family:'Courier New', courier, monospace;direction:ltr;border-top-style:none;color:black;font-size:8pt;border-left-style:none;overflow:visible;padding-top:0px"><span style="color:#606060" id=lnum22>  22:</span> }</pre></div></div>
<p>What this does before the query is executed to SharePoint, is:</p>
<ul>
<li>get a reference to the SharePoint group</li>
<li>find the selected user in the site users</li>
<li>add the user to the selected group</li>
<li>find the role assignment for the selected user</li>
<li>delete the role assignment for the selected user</li></ul>
<p>By submitting the query to SharePoint, all these actions are all executed at once in 1 roundtrip to the server. If this action is successful, the javascript function addUsersSucceeded is called. This function has not specical function, it notifies the user about the outcome of the process.</p>
<p>In this article we have seen how to use one of the three new client object models, the ECMAScript library. Although programming client applications is now a lot easier, and is more like programming the server, the are some conceptual differences that are important to understand. The next few articles will show you some examples on how to get started using the other two client object models.</p></div></div>
<div><b>Published:</b> 11/3/2009 11:51 AM</div>
<div><b>Attachments:</b> <a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/118/ClientObjectModelsFiguur3_2_12FC64E0.jpg">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/118/ClientObjectModelsFiguur3_2_12FC64E0.jpg</a><br><a href="http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/118/ClientObjectModelsFiguur3_thumb_12FC64E0.jpg">http://www.tonstegeman.com/Blog/Lists/Posts/Attachments/118/ClientObjectModelsFiguur3_thumb_12FC64E0.jpg</a><br><a href=""></a></div>
]]></description>
      <author>Ton Stegeman</author>
      <pubDate>Tue, 03 Nov 2009 19:51:51 GMT</pubDate>
      <guid isPermaLink="true">http://www.tonstegeman.com/Blog/Lists/Posts/ViewPost.aspx?ID=118</guid>
    </item>
  </channel>
</rss>
