<?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; runwithelevatedprivileges</title>
	<atom:link href="http://sharepointsharpener.wordpress.com/tag/runwithelevatedprivileges/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; runwithelevatedprivileges</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>
	</channel>
</rss>