<?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 &#187; C#</title>
	<atom:link href="http://www.sharepointboris.net/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sharepointboris.net</link>
	<description>and Boris Gomiunik</description>
	<lastBuildDate>Thu, 22 Dec 2011 11:45:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>SharePoint Document Library item title in Event Receiver AfterProperties</title>
		<link>http://www.sharepointboris.net/2010/01/sharepoint-document-library-item-title-in-event-receiver-afterproperties/</link>
		<comments>http://www.sharepointboris.net/2010/01/sharepoint-document-library-item-title-in-event-receiver-afterproperties/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 07:32:53 +0000</pubDate>
		<dc:creator>Boris Gomiunik</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[AfterProperties]]></category>
		<category><![CDATA[Event Receivers]]></category>

		<guid isPermaLink="false">http://www.sharepointboris.net/2010/01/sharepoint-document-library-item-title-in-event-receiver-afterproperties/</guid>
		<description><![CDATA[Here&#8217;s a short one worth taking note of. If you&#8217;re using SharePoint Event Receivers – more specifically synchronous event receivers (-ing) you might notice that if you try to set Properties.AfterProperties[&#34;Title&#34;] in a document library for the strangest reason it doesn&#8217;t work. If that occurs, use the AfterProperties[&#34;vti_title&#34;] And the Document Title can be managed.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a short one worth taking note of. If you&#8217;re using SharePoint Event Receivers – more specifically synchronous event receivers (-ing) you might notice that if you try to set Properties.AfterProperties[&quot;Title&quot;] in a document library for the strangest reason it doesn&#8217;t work. If that occurs, use the </p>
<p><strong>AfterProperties[&quot;vti_title&quot;]</strong></p>
<p><font color="#000000">And the Document Title can be managed.</font></p>
<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sharepointboris.net/2010/01/sharepoint-document-library-item-title-in-event-receiver-afterproperties/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SPSecurity.RunWithElevatedPrivileges and Access Denied error on event receiver</title>
		<link>http://www.sharepointboris.net/2009/04/spsecurityrunwithelevatedprivileges-and-access-denied-error-on-event-receiver/</link>
		<comments>http://www.sharepointboris.net/2009/04/spsecurityrunwithelevatedprivileges-and-access-denied-error-on-event-receiver/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 11:25:06 +0000</pubDate>
		<dc:creator>Boris Gomiunik</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://boris.gomiunik.net/2009/04/spsecurityrunwithelevatedprivileges-and-access-denied-error-on-event-receiver/</guid>
		<description><![CDATA[After looksing half a day for a st00pid mistake I have to write about this to warn anyone that might run into similar problem. In VS I’ve prepared a custom event receiver which needed to be run as system account (for performing actions that the user running the event receiver doesn’t have – like setting [...]]]></description>
			<content:encoded><![CDATA[<p>After looksing half a day for a st00pid mistake I have to write about this to warn anyone that might run into similar problem.</p>
<p>In VS I’ve prepared a custom event receiver which needed to be run as system account (for performing actions that the user running the event receiver doesn’t have – like setting permissions, creating subwebs,…)</p>
<p>So my code began with something lilke that:</p>
<p>…</p>
<p>public override void ItemUpdated(SPItemEventProperties properties)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; base.ItemUpdated(properties);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _properties = properties; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //povišamo pravice na sistemski račun in zaženemo private metodo   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPSecurity.RunWithElevatedPrivileges(doSomethingWithThis);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private void doSomethingWithThis()   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; { </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPSite site = new SPSite(_properties.SiteId);   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPWeb web = site.OpenWeb(_properties.RelativeWebUrl);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPListItem item = web.Lists[_properties.ListItem]</p>
<p>…</p>
<p>after running it and tracing the error I’ve always received “Access denied” error. How come, if I’m running the code with elevated privileges. Do I need even a higher privilege?</p>
<p>After countless attempts to impersonate an administrator or app pool account (I’m still a rookie at this), I’ve discovered that the SPItemEventProperties are instantiated with privileges of user that triggered the event receiver. The error was in my last line (of the example above) &#8212; <strong>_properties.ListItem</strong> still holds the rights of the original user. so fixed my code to</p>
<p>…</p>
<p>public override void ItemUpdated(SPItemEventProperties properties)   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; base.ItemUpdated(properties);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; _properties = properties; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //povišamo pravice na sistemski račun in zaženemo private metodo   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPSecurity.RunWithElevatedPrivileges(ustvariPonudbaSubsite);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private void ustvariPonudbaSubsite()   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; { </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPSite site = new SPSite(_properties.SiteId);   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPWeb web = site.OpenWeb(_properties.RelativeWebUrl);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SPListItem item = web.Lists[<strong>_properties.ListId].GetItemById(_properties.ListItem.ID</strong>);</p>
<p>…</p>
<p>With that change I’ve open the SPListItem object as system account and magically everything started working as it should! The same goes for site and web object. If you need to run actions with elevated privileges on SPSite and SPWeb object use</p>
<p><strong>new SPSite(_properties.SiteId);     <br /></strong>and    <br /><strong>site.OpenWeb(_properties.RelativeWebUrl)</strong> </p>
<p>instead of </p>
<p><strong>_properties.web</strong>    <br />and    <br /><strong>web.site;</strong></p>
<div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:2692cfb0-c1e1-472f-95b0-dcce40c8b158" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags: <a href="http://technorati.com/tags/SharePoint" rel="tag">SharePoint</a>,<a href="http://technorati.com/tags/programming" rel="tag">programming</a>,<a href="http://technorati.com/tags/c%23" rel="tag">c#</a>,<a href="http://technorati.com/tags/event+receiver" rel="tag">event receiver</a>,<a href="http://technorati.com/tags/user+rights" rel="tag">user rights</a></div>
<p><!-- PHP 5.x --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sharepointboris.net/2009/04/spsecurityrunwithelevatedprivileges-and-access-denied-error-on-event-receiver/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>

