<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>SharePoint Sharpener &#187; web part</title>
	<atom:link href="http://sharepointsharpener.wordpress.com/tag/web-part/feed/" rel="self" type="application/rss+xml" />
	<link>http://sharepointsharpener.wordpress.com</link>
	<description>Obsessively Sharpening SharePoint</description>
	<lastBuildDate>Mon, 19 Oct 2009 21:48:56 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='sharepointsharpener.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/a13c576c6a4d38c391bc0a6d1d7261ba?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>SharePoint Sharpener &#187; web part</title>
		<link>http://sharepointsharpener.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://sharepointsharpener.wordpress.com/osd.xml" title="SharePoint Sharpener" />
		<item>
		<title>Elevation: Run Code as an Administrator</title>
		<link>http://sharepointsharpener.wordpress.com/2008/08/27/elevation-run-code-as-an-administrator/</link>
		<comments>http://sharepointsharpener.wordpress.com/2008/08/27/elevation-run-code-as-an-administrator/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 06:56:51 +0000</pubDate>
		<dc:creator>Thomas Sondergaard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[credentials]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[elevation]]></category>
		<category><![CDATA[privileges]]></category>
		<category><![CDATA[runwithelevatedprivileges]]></category>
		<category><![CDATA[spsecurity]]></category>
		<category><![CDATA[unauthorized]]></category>
		<category><![CDATA[web part]]></category>

		<guid isPermaLink="false">http://sharepointsharpener.wordpress.com/2008/08/27/elevation-run-code-as-an-administrator/</guid>
		<description><![CDATA[Sometimes you may need your web part to perform tasks for which the current user doesn&#8217;t have priviliges. For instance, we needed a sign up form for our WCM web site where the user could enter contact information that should be stored in a list.
Naturally, our web site runs with anonymous access and the the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sharepointsharpener.wordpress.com&blog=4068218&post=49&subd=sharepointsharpener&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Sometimes you may need your web part to perform tasks for which the current user doesn&#8217;t have priviliges. For instance, we needed a sign up form for our WCM web site where the user could enter contact information that should be stored in a list.</p>
<p>Naturally, our web site runs with anonymous access and the the anonymous users do not have access to the underlying lists, including the list where the contact information goes.</p>
<p>Thus, submitting to the list is not just a matter of doing an <em>Items.Add()</em> because this causes a login dialogue to pop up and ultimately a <em>401 Unauthorized</em> error.</p>
<p>Normally you&#8217;d create an element in the list with code similar to this:</p>
<p><img style="border-width:0;" height="169" alt="image" src="http://sharepointsharpener.files.wordpress.com/2008/08/image.png?w=501&#038;h=169" width="501" border="0"> </p>
<p>&nbsp;</p>
<p>However, if the logged-in user doesn&#8217;t have sufficient credentials to write to the list, a login dialogue will pop up.</p>
<p>&nbsp;</p>
<p><strong>Run with Elevation</strong></p>
<p>To get around this problem you can use <em>SPSecurity.RunWithElevatedPriviliges()</em> like this:</p>
<p><img style="border-width:0;" height="103" alt="image" src="http://sharepointsharpener.files.wordpress.com/2008/08/image1.png?w=406&#038;h=103" width="406" border="0"> </p>
<p>&nbsp;</p>
<p>For this to work, you need to instantiate the SPSite and SPWeb objects inside <em>delegate()</em>:</p>
<p><img style="border-width:0;" height="351" alt="image" src="http://sharepointsharpener.files.wordpress.com/2008/08/image2.png?w=621&#038;h=351" width="621" border="0"></p>
<p>&nbsp;</p>
<p>Now the list will be updated with a new element, created by the system account. </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sharepointsharpener.wordpress.com/49/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sharepointsharpener.wordpress.com/49/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sharepointsharpener.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sharepointsharpener.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sharepointsharpener.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sharepointsharpener.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sharepointsharpener.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sharepointsharpener.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sharepointsharpener.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sharepointsharpener.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sharepointsharpener.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sharepointsharpener.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sharepointsharpener.wordpress.com&blog=4068218&post=49&subd=sharepointsharpener&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sharepointsharpener.wordpress.com/2008/08/27/elevation-run-code-as-an-administrator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0dfb315d39c37443371df076767fa665?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thomassondergaard</media:title>
		</media:content>

		<media:content url="http://sharepointsharpener.files.wordpress.com/2008/08/image.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sharepointsharpener.files.wordpress.com/2008/08/image1.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sharepointsharpener.files.wordpress.com/2008/08/image2.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
		<item>
		<title>UserProfileService Web Service Returns Multiple Instances of User Profiles with Identical Names</title>
		<link>http://sharepointsharpener.wordpress.com/2008/08/08/userprofileservice-web-service-returns-multiple-instances-of-user-profiles-with-identical-names/</link>
		<comments>http://sharepointsharpener.wordpress.com/2008/08/08/userprofileservice-web-service-returns-multiple-instances-of-user-profiles-with-identical-names/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 16:23:17 +0000</pubDate>
		<dc:creator>Thomas Sondergaard</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[user profile]]></category>
		<category><![CDATA[web part]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://sharepointsharpener.wordpress.com/2008/08/08/userprofileservice-web-service-returns-multiple-instances-of-user-profiles-with-identical-names/</guid>
		<description><![CDATA[The lack of a built-in overview of all users in SharePoint makes it difficult to create a simple phone book of your company&#8217;s employees. The object UserProfileManager would be the obvious starting point if you were to create your own phone book for SharePoint &#8211; and many have tried this. Google this object and you&#8217;ll [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sharepointsharpener.wordpress.com&blog=4068218&post=42&subd=sharepointsharpener&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The lack of a built-in overview of all users in SharePoint makes it difficult to create a simple phone book of your company&#8217;s employees. The object <em><a href="http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofilemanager.aspx" target="_blank">UserProfileManager</a></em> would be the obvious starting point if you were to create your own phone book for SharePoint &#8211; and many have tried this. <a href="http://www.google.co.uk/search?hl=en&amp;q=UserProfileManager" target="_blank">Google this object</a> and you&#8217;ll find that the only real way to query all users effectively is using the built-in web services of MOSS.</p>
<p>Specifically, <em><a href="http://msdn.microsoft.com/en-us/library/aa980957.aspx" target="_blank">UserProfileService</a></em> (http://server/_vti_bin/userprofileservice.asmx) is ideal for querying user profiles from e.g. within a web part.</p>
<p>In Visual Studio, when you&#8217;ve set up the web service, you connect to the web services like so:</p>
<p><img style="border-width:0;" src="http://sharepointsharpener.files.wordpress.com/2008/08/image3.png?w=648&#038;h=78" border="0" alt="image" width="648" height="78" /></p>
<p>Then, you can query the number of profiles in the user profile database by calling the method <em><a href="http://msdn.microsoft.com/en-us/library/websvcuserprofileservice.userprofileservice.getuserprofilecount.aspx" target="_blank">GetUserProfileCount</a></em>:</p>
<p><img style="border-width:0;" src="http://sharepointsharpener.files.wordpress.com/2008/08/image4.png?w=433&#038;h=57" border="0" alt="image" width="433" height="57" /></p>
<p>Knowing the number of user profiles, you can iterate through them and pull the user data:</p>
<p><img style="border-width:0;" src="http://sharepointsharpener.files.wordpress.com/2008/08/image5.png?w=656&#038;h=174" border="0" alt="image" width="656" height="174" /></p>
<p><strong>Some names show up several times</strong></p>
<p>You will find, however, that <em><a href="http://msdn.microsoft.com/en-us/library/aa981288.aspx" target="_blank">GetUserProfileByIndex</a></em> only holds information about users whom have active MySites. Strangely enough, even if the total number of users exceed the number of users with MySites, you can still iterate through all the user profiles you found with <em>GetUserProfileCount</em>.</p>
<p>Say, you have the following people in your User Profile database:</p>
<p>1 &#8211; Ted Pattison<br />
2 &#8211; Liam Cleary<br />
3 &#8211; Amanda Murphy<br />
4 &#8211; Yvonne Harryman<br />
5 &#8211; Steve Pietrek</p>
<p>Let&#8217;s assume that Amanda and Yvonne don&#8217;t have MySites. Then the output of the above loop would look like this:</p>
<p>1 &#8211; Ted Pattison<br />
2 &#8211; Liam Cleary<br />
3 &#8211; Liam Cleary<br />
4 &#8211; Liam Cleary<br />
5 &#8211; Steve Pietrek</p>
<p><em>GetUserProfileByIndex</em> will not fail when you loop through 5 profiles because that is the number of profiles present in the database. On the other hand, querying a profile that doesn&#8217;t have a MySite, e.g. <em>GetUserProfileByIndex(3)</em> and <em>GetUserProfileByIndex(4)</em>, will return the latest user with a MySite, in this case Liam Cleary (index no. 2).</p>
<p><strong>Solution</strong></p>
<p>In order to avoid this situation the value stored in <em>NextValue</em> can be used. <em>NextValue</em> contains the index of the next user with a valid MySite user profile. Looking at the first table again, the <em>NextValue</em> values are shown in parentheses:</p>
<p>1 &#8211; Ted Pattison (2)<br />
2 &#8211; Liam Cleary (5)<br />
3 &#8211; Amanda Murphy (5)<br />
4 &#8211; Yvonne Harryman (5)<br />
5 &#8211; Steve Pietrek ()</p>
<p>The following line can then be added to the loop to ensure that the next profile to be shown contains usable information:</p>
<p><img style="border-width:0;" src="http://sharepointsharpener.files.wordpress.com/2008/08/image6.png?w=528&#038;h=52" border="0" alt="image" width="528" height="52" /></p>
<p>Now you just need to output all the information in an SPGridView and the phone book is ready to be implemented.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/sharepointsharpener.wordpress.com/42/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/sharepointsharpener.wordpress.com/42/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/sharepointsharpener.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/sharepointsharpener.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/sharepointsharpener.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/sharepointsharpener.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/sharepointsharpener.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/sharepointsharpener.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/sharepointsharpener.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/sharepointsharpener.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/sharepointsharpener.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/sharepointsharpener.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=sharepointsharpener.wordpress.com&blog=4068218&post=42&subd=sharepointsharpener&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://sharepointsharpener.wordpress.com/2008/08/08/userprofileservice-web-service-returns-multiple-instances-of-user-profiles-with-identical-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/0dfb315d39c37443371df076767fa665?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">thomassondergaard</media:title>
		</media:content>

		<media:content url="http://sharepointsharpener.files.wordpress.com/2008/08/image3.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sharepointsharpener.files.wordpress.com/2008/08/image4.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sharepointsharpener.files.wordpress.com/2008/08/image5.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>

		<media:content url="http://sharepointsharpener.files.wordpress.com/2008/08/image6.png" medium="image">
			<media:title type="html">image</media:title>
		</media:content>
	</item>
	</channel>
</rss>