<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Sohail Sayed's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/sasohail/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/sasohail/feed.xml</link>
    <description />
    <lastBuildDate>Tue, 16 Apr 2019 05:51:07 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Fixing error "The file |0 does not exist." when calling the endpoint "/_api/v1.0/files/root/children" in SharePoint online</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/fixing-error-the-file-0-does-not-exist-when-calling-the-endpoint-_apiv1-0filesrootchildren-in-sharepoint-online</link>
      <pubDate>Fri, 28 Apr 2017 06:22:01 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/?p=146</guid>
      <description><![CDATA[We came across an issue where we were getting an error when calling the...]]></description>
      <content:encoded><![CDATA[We came across an issue where we were getting an error when calling the endpoint "/_api/v1.0/files/root/children" on a SharePoint site in Office 365.

There are no additional details in the error message.

The fix for this error is very simple however the error message itself is not very friendly.

The endpoint gets the documents from the default document library and we will see this error if the default document library is deleted.

In most cases this will be a library named Documents.

Recreating this library will fix this error.

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>Fixing error “The Request uses too many resources.” In CSOM / REST operation</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/fixing-error-the-request-uses-too-many-resources-in-csom-rest-operation</link>
      <pubDate>Wed, 19 Oct 2016 00:32:22 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/?p=145</guid>
      <description><![CDATA[Added a new blog post on SharePoint Developer Support Team Blog.

Below is the...]]></description>
      <content:encoded><![CDATA[Added a new blog post on SharePoint Developer Support Team Blog.

Below is the link

https://blogs.technet.microsoft.com/sharepointdevelopersupport/2016/10/19/fixing-error-the-request-uses-too-many-resources-in-csom-rest-operation/]]></content:encoded>
    </item>
    <item>
      <title>Approving list items through REST call in SharePoint 2013 Workflows using HttpSend Activity fails</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/approving-list-items-through-rest-call-in-sharepoint-2013-workflows-using-httpsend-activity-fails</link>
      <pubDate>Wed, 09 Sep 2015 15:15:00 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2015/09/09/approving-list-items-through-rest-call-in-sharepoint-2013-workflows-using-httpsend-activity-fails/</guid>
      <description><![CDATA[REST services in SharePoint 2013 have become really powerful and enable to do a wide range of...]]></description>
      <content:encoded><![CDATA[<p>REST services in SharePoint 2013 have become really powerful and enable to do a wide range of operations.</p>
<p>One of the scenarios is updating and approving list items.through REST service.</p>
<p>While i will not go in details on using the REST services (there are multiple samples already available on net)&nbsp;&nbsp;you can see that we can easily update list items through REST. For Approving items we set the OData__ModerationStatus to 0.</p>
<p>This works fine in most cases but in case of SharePoint 2013 workflow you will find that approving items fails though updating list items goes through fine.</p>
<p>The SharePoint&nbsp;2013 workflows are really like provider hosted apps and have a default set of permissions which does not include approve items permission.</p>
<p>&nbsp;Perform the below steps to fix this</p>
<p>&nbsp;<br />Go to "Site Settings" "Site App Permissions"</p>
<p>Find the App Workflow as copy the first guid as shown below</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/8204.siteappperm.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/8204.siteappperm.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/8204.siteappperm.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x500/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/8204.siteappperm.png" alt="" border="0" /></a><br />Go to <a href="http://%3csite">http://&lt;site</a> collection Url&gt;/_layouts/15/appInv.aspx.</p>
<p>Enter the Guid copied in previous step in the App ID and click on Lookup.</p>
<p>This will populate the Title, App Domain and Redirect URL columns.</p>
<p>Copy the below in Permission Request XML (copy as is and do not change the url in the Scope)</p>
<p>&lt;AppPermissionRequests&gt;</p>
<p>&nbsp;&nbsp;&nbsp; &lt;AppPermissionRequest<br />Scope="<a href="http://sharepoint/content/sitecollection/web">http://sharepoint/content/sitecollection/web</a>"<br />Right="FullControl" /&gt;</p>
<p>&nbsp; &lt;/AppPermissionRequests&gt;</p>
<p>&nbsp;</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/5657.wfperm.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/5657.wfperm.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/5657.wfperm.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x700/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/5657.wfperm.png" alt="" border="0" /></a></p>
<p>Click on Create and Trust the Workflow App</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/3286.trustwf.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/3286.trustwf.jpg"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/3286.trustwf.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/3286.trustwf.jpg" alt="" border="0" /></a></p>
<p>Test the workflow again and it should start working.</p>
<p>Note the list item needs to be in Pending state else the Approval with not work even with these steps.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>Calling BCS FindFiltered method on BCS from Client Object Model throws An exception of type 'Microsoft.SharePoint.Client.ServerException' occurred in Microsoft.SharePoint.Client.Runtime.dll but was not handled in user code</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/calling-bcs-findfiltered-method-on-bcs-from-client-object-model-throws-an-exception-of-type-microsoft-sharepoint-client-serverexception-occurred-in-microsoft-sharepoint-client-runtime-dll-but-was-no</link>
      <pubDate>Wed, 09 Sep 2015 14:23:00 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2015/09/09/calling-bcs-findfiltered-method-on-bcs-from-client-object-model-throws-an-exception-of-type-microsoft-sharepoint-client-serverexception-occurred-in-microsoft-sharepoint-client-runtime-dll-but-was-no/</guid>
      <description><![CDATA[Recently I cam across an interesting issue from a customer where customer was calling the...]]></description>
      <content:encoded><![CDATA[<p>Recently I cam across an interesting issue from a customer where customer was calling the FindFiltered method of external content type to get filtered items.</p>
<p>Following is the sample code that calls the FindFiltered method.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string readListInstanceName = ConfigurationManager.AppSettings["method"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.BusinessData.MetadataModel.Entity entity = clientContext.Web.GetEntity(ConfigurationManager.AppSettings["namespace"], ConfigurationManager.AppSettings["name"]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.BusinessData.MetadataModel.LobSystem lobSystem = entity.GetLobSystem();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.BusinessData.MetadataModel.Collections.LobSystemInstanceCollection lobSystemInstanceCollection = lobSystem.GetLobSystemInstances();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientContext.Load(lobSystemInstanceCollection);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientContext.Load(entity);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientContext.ExecuteQuery();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.BusinessData.MetadataModel.LobSystemInstance lobSystemInstance = lobSystemInstanceCollection[0];</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.BusinessData.MetadataModel.Collections.FilterCollection externalFiltersOnFieldCollection = entity.GetFilters(readListInstanceName);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;string&gt; searchFilters = new List&lt;string&gt;();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientContext.Load(externalFiltersOnFieldCollection);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientContext.ExecuteQuery();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (Microsoft.BusinessData.MetadataModel.Filter filter in externalFiltersOnFieldCollection)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (filter.FilterField.Equals(ConfigurationManager.AppSettings["filter"]))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; searchFilters.Add(filter.Name);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (string filterName in searchFilters)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; externalFiltersOnFieldCollection.SetFilterValue(filterName, 0, ConfigurationManager.AppSettings["filtervalue"]);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.BusinessData.MetadataModel.Collections.EntityInstanceCollection result = entity.FindFiltered(externalFiltersOnFieldCollection, readListInstanceName, lobSystemInstance);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientContext.Load(result);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientContext.ExecuteQuery();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result;</p>
<p>Calling clientContext.ExecuteQuery(); was throwing an error - "An exception of type 'Microsoft.SharePoint.Client.ServerException' occurred in Microsoft.SharePoint.Client.Runtime.dll but was not handled in user code System.ArgumentNullException: Value cannot be null.&nbsp; Parameter<br />name: unescapedStr&nbsp;&nbsp;&nbsp;"</p>
<p>The resolution of this issue was pretty straight forward but not very obvious.</p>
<p>This exception is thrown when a BCS Model Does not contain the ReadItem aka SpecificFinder method.</p>
<p>Now the question arises why does calling the BCS Read List method require the ReadItem method.</p>
<p>If we look at the stack trace in ULS log we see the following</p>
<p>Exception occured in scope Microsoft.SharePoint.BusinessData.MetadataModel.Collections.AbstractEntityInstanceCollection._SerializeToJson.<br />Exception=System.ArgumentNullException: Value cannot be null.&nbsp; Parameter<br />name: unescapedStr&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;at Microsoft.BusinessData.Infrastructure.Util.Escape(Char<br />valueToEscape, String unescapedStr)&nbsp;&nbsp;&nbsp;&nbsp;at<br />Microsoft.SharePoint.BusinessData.BCSObjectFactory.GetEntityInstanceCanonicalId(IEntityInstance<br />entityInstance)&nbsp;&nbsp;&nbsp;&nbsp;at<br />Microsoft.BusinessData.ServerStub.Runtime.AbstractEntityInstanceServerStub.GetObjectIdentity(Object<br />target)&nbsp;&nbsp;&nbsp;&nbsp;at<br />Microsoft.SharePoint.Client.ServerStub.WriteAsJson(JsonWriter writer, Object<br />obj, ClientObjectQuery objectQuery, ProxyContext<br />proxyContext)&nbsp;&nbsp;&nbsp;&nbsp;at<br />Microsoft.SharePoint.Client.ServerStub.WriteChildItems(JsonWriter writer,<br />Object obj, ClientObjectQuery objectQuery, ProxyContext<br />proxyContext)&nbsp;&nbsp;&nbsp;&nbsp;at<br />Microsoft.SharePoint.Client.ServerStub.WriteAsJson(JsonWriter writer, Object<br />obj, ClientObjectQuery objectQuery, ProxyContext<br />proxyContext)&nbsp;&nbsp;&nbsp;&nbsp;at<br />Microsoft.SharePoint.Client.ServerStub.WriteAsJsonWithMonitoredScope(JsonWriter<br />writer, Object value, ClientObjectQuery objectQuery, ProxyContext proxyCon</p>
<p>The exception is actually thrown at Microsoft.BusinessData.Infrastructure.Util.Escape but the real error happens at Microsoft.SharePoint.BusinessData.BCSObjectFactory.GetEntityInstanceCanonicalId</p>
<p>It seems like the API internally uses the name of the ReadItem method to generate an identifier used internally&nbsp;(i didn't go into further details on where this is used ).</p>
<p>If the ReadItem method does not exist null is passed to the Microsoft.BusinessData.Infrastructure.Util.Escape method which does some kind of encoding of strings and the above exception is thrown.</p>
<p>Though i cannot really visualize a scenario where we don't need the ReadItem method I tried to find any documentation where it is mentioned that ReadItem is required in BCS Model.</p>
<p>I couldn't find any specific documentation but can see that all samples always include the ReadItem method.</p>
<p>Also if you make the External Content Type in SharePoint Designer you should be able to see a warning message if you don't have the ReadItem method.<span style="font-family: 'Calibri',sans-serif; font-size: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;"><br /><br />&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/3225.SPD_error.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/3225.SPD_5F00_error.jpg"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/3225.SPD_error.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/3225.SPD_5F00_error.jpg" alt="" border="0" /></a></span></p>
<p><span style="font-family: 'Calibri',sans-serif; font-size: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">I will conclude that it is safe to say that ReadItem is a required method in the External Content Type.</span></p>
<p><span style="font-family: 'Calibri',sans-serif; font-size: 11pt; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA;">Hopefully this post will save someone the pain of further troubleshooting when they come across this issue.</span></p>]]></content:encoded>
    </item>
    <item>
      <title>Permissions considerations when calling O365 APIs</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/permissions-considerations-when-calling-o365-apis</link>
      <pubDate>Thu, 23 Apr 2015 14:58:00 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2015/04/23/permissions-considerations-when-calling-o365-apis/</guid>
      <description><![CDATA[&nbsp;
Recently I did a small Proof Of Concept Application that called the Office 365 APIs to...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;</p>
<p>Recently I did a small Proof Of Concept Application that called the Office 365 APIs to access data from a SharePoint site collection and performed some other operations that require higher rights like Creating lists.This was done to verify the way the user permissions&nbsp;in SharePoint and the permissions provided to the application in windows azure impact what data the application can access.</p>
<p>Though this App was done with a windows application in .Net this should be applicable to all the other platforms that use the corresponding O365 API as they call the same underlying infrastructure in Office 365.</p>
<p>The App did the following operations in a SharePoint site.</p>
<ul>
<li>View List Items</li>
<li>Create List Items</li>
<li>Create Lists</li>
</ul>
<p>The App was tested with following set of permissions</p>
<ul>
<li>Full Control</li>
<li>View /Add . Edit list Items</li>
<li>View List Items</li>
</ul>
<p>In addition the App was tested with following types of users</p>
<ul>
<li>Global Administrator (Azure)</li>
<li>Site collection Admin \ Full Control</li>
<li>Members \ Contribute permissions</li>
<li>Visitors \ Read permission</li>
</ul>
<p>&nbsp;</p>
<p>Based on my tests I could come up with the below matrix for permissions. Please note there is currently no official documentation around this and the results are based on testing at my side.</p>
<p>These results should remain the same across the various platform on which the the APIs are called as the underlying infrastructure is same.</p>
<p>Also the scope of the Client Application is limited to retrieving the appropriate tokens and the permissions for an app will depend upon the permissions provided to the App in Azure + the right that the logged in user has</p>
<p>&nbsp;One more point I need to mention is that I found some time lag before I could do some operation with a new user once the user is created.<br />&nbsp;&nbsp;</p>
<p>The API was tested for SharePoint only and the below matrix is applicable for SharePoint only.</p>
<p>&nbsp;&nbsp;</p>
<p><strong>Following is the matrix </strong></p>
<p>&nbsp;</p>
<ol>
<li><strong><span style="text-decoration: underline;">App has full controls</span></strong></li>
</ol>
<p>Following are the app permissions set in Azure for App</p>
<p><br />&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/8738.All%20Perms.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/8738.All-Perms.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/8738.All%20Perms.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/8738.All-Perms.png" alt="" border="0" /></a></p>
<p>Below are the permission that the application will actually have based on the currently logged in user's rights.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="bottom" nowrap="nowrap" width="188">
<p><strong>User Rights</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="115">
<p><strong>Can Create List</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p><strong>Can Create List Items</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="113">
<p><strong>Can Read List Items</strong></p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="188">
<p>Global Administrator (Azure)</p>
</td>
<td valign="bottom" nowrap="nowrap" width="115">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="113">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="188">
<p>Site collection Admin \ Full<br /><br />&nbsp; &nbsp; Control</p>
</td>
<td valign="bottom" nowrap="nowrap" width="115">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="113">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="188">
<p>Members \ Contribute permissions</p>
</td>
<td valign="bottom" nowrap="nowrap" width="115">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="113">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="188">
<p>Visitors \ Read permission</p>
</td>
<td valign="bottom" nowrap="nowrap" width="115">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="113">
<p>Yes</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p><strong><span style="text-decoration: underline;">2. App has read and write permissions on lists but not create lists</span></strong></p>
<p>Following are the app permissions set in Azure for the App</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/1778.readEditPerms.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/1778.readEditPerms.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/1778.readEditPerms.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/1778.readEditPerms.png" alt="" border="0" /></a></p>
<p>&nbsp;</p>
<p>Below are the permission that the application will actually have based on the currently logged in user's rights.</p>
<p>&nbsp;</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="bottom" nowrap="nowrap" width="259">
<p><strong>User Rights</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="108">
<p><strong>Can Create List</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="121">
<p><strong>Can Create List Items</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="104">
<p><strong>Can Read List Items</strong></p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="259">
<p>Global Administrator (Azure)</p>
</td>
<td valign="bottom" nowrap="nowrap" width="108">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="121">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="104">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="259">
<p>Site collection Admin \ Full<br /><br />&nbsp; &nbsp; Control</p>
</td>
<td valign="bottom" nowrap="nowrap" width="108">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="121">
<p>Yes</p>
</td>
<td valign="bottom" nowrap="nowrap" width="104">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="259">
<p>Members \ Contribute permissions</p>
</td>
<td valign="bottom" nowrap="nowrap" width="108">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="121">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="104">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="259">
<p>Visitors \ Read permission</p>
</td>
<td valign="bottom" nowrap="nowrap" width="108">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="121">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="104">
<p>Yes</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong>3.&nbsp;</strong><strong><span style="text-decoration: underline;">App has only read permissions on lists </span></strong></p>
<p>Following are the permissions set in Azure for the App</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/5584.readperms.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/5584.readperms.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/5584.readperms.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-29-79/5584.readperms.png" alt="" border="0" /></a></p>
<p>&nbsp;&nbsp;</p>
<p>Below are the permission that the application will actually have based on the currently logged in user's rights.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="bottom" nowrap="nowrap" width="245">
<p><strong>User Rights</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p><strong>Can Create List</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="128">
<p><strong>Can Create List Items</strong></p>
</td>
<td valign="bottom" nowrap="nowrap" width="111">
<p><strong>Can Read List Items</strong></p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="245">
<p>Global Administrator (Azure)</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="128">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="111">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="245">
<p>Site collection Admin \ Full<br /><br />&nbsp; &nbsp; Control</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="128">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="111">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="245">
<p>Members \ Contribute permissions</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="128">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="111">
<p>Yes</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="245">
<p>Visitors \ Read permission</p>
</td>
<td valign="bottom" nowrap="nowrap" width="123">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="128">
<p>No</p>
</td>
<td valign="bottom" nowrap="nowrap" width="111">
<p>Yes</p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<table style="width: 842px;" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="bottom" nowrap="nowrap" width="358">&nbsp;</td>
<td valign="bottom" nowrap="nowrap" width="145">
<p><strong></strong>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="153">
<p><strong></strong>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="185">
<p><strong></strong>&nbsp;</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="358">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="145">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="153">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="185">
<p>&nbsp;</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="358">
<p><br />&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="145">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="153">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="185">
<p>&nbsp;</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="358">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="145">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="153">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="185">
<p>&nbsp;</p>
</td>
</tr>
<tr>
<td valign="bottom" nowrap="nowrap" width="358">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="145">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="153">
<p>&nbsp;</p>
</td>
<td valign="bottom" nowrap="nowrap" width="185">
<p>&nbsp;</p>
<p>&nbsp;</p>
</td>
</tr>
</tbody>
</table>]]></content:encoded>
    </item>
    <item>
      <title>Reassign workflow task using the workflow web service - AlterToDo method</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/reassign-workflow-task-using-the-workflow-web-service-altertodo-method</link>
      <pubDate>Thu, 09 Apr 2015 20:45:00 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2015/04/09/reassign-workflow-task-using-the-workflow-web-service-altertodo-method/</guid>
      <description><![CDATA[SharePoint provides a web service workflow.asmx. This is available under /_vti_bin/workflow.asmx and...]]></description>
      <content:encoded><![CDATA[<p>SharePoint provides a web service workflow.asmx. This is available under /_vti_bin/workflow.asmx and provides an operation AlterToDo which enables to update the task and also reassign the tasks.</p>
<p>I recently had a customer who was having issues with the AlterToDo. Customer was calling the AlterToDo method of the workflow.asmx as per the documentation available but the task was not getting reassigned.</p>
<p>On researching further we could see that there is no accurate documentation on the internet for using the AlterToDo method to reassign tasks.</p>
<p>Following is the code sample which calls the AlterToDo method.</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strURL = "<a href="http://sp/documents/doc1.docx">http://sp/documents/doc1.docx</a>";</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // task item id<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int intToDo = 1;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Task list id<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Guid GUIDToDoListID = new Guid("{f46aa19e-ea35-4357-80f4-882306a2ebdc}");</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WorkflowService.Workflow client = new WorkflowService.Workflow();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; client.Credentials = CredentialCache.DefaultCredentials;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="background-color: #ffff00;"> string strData = "" ; /*Some xml comes here */</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XmlDocument XMLTaskData = new XmlDocument();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; XMLTaskData.LoadXml(strData);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var data3 = client.AlterToDo(strURL, intToDo, GUIDToDoListID, <span style="background-color: #ffff00;">XMLTaskData</span>);</p>
<p>&nbsp;</p>
<p>By accurate documentation I am referring to the xml sent to AlterToDo method.</p>
<p>Following is the correct xml to reassign a task.</p>
<p>var strData = @"&lt;my:myFields xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD'&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;my:TaskStatus&gt;ReassignTask&lt;/my:TaskStatus&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;my:Comments&gt;&lt;/my:Comments&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;my:FieldName_DelegateTo&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;pc:Person xmlns:pc=""<a href="http://schemas.microsoft.com/office/infopath/2007/PartnerControls">http://schemas.microsoft.com/office/infopath/2007/PartnerControls</a>""&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;pc:DisplayName&gt;User 2&lt;/pc:DisplayName&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;pc:AccountId&gt;contoso\user2&lt;/pc:AccountId&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;pc:AccountType&gt;User&lt;/pc:AccountType&gt;&lt;/pc:Person&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/my:FieldName_DelegateTo&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/my:myFields&gt;";</p>
<p>I haven't seen this method being used very widely. But when it is being used it can be a bummer to get this working without the correct xml to reassign tasks.</p>
<p>Thanks to my Escalation Engineer Andy Li for helping in figuring this out.</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
    <item>
      <title>The magic of Hyper-V</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/the-magic-of-hyper-v</link>
      <pubDate>Sat, 18 Dec 2010 23:49:00 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2010/12/18/the-magic-of-hyper-v/</guid>
      <description><![CDATA[Last few days i have been witnessing the power of Hyper-V - the microsoft virtualization solution...]]></description>
      <content:encoded><![CDATA[<p>Last few days i have been witnessing the power of Hyper-V - the microsoft virtualization solution and could not resist myself from blogging about it.</p>
<p>We have a complex sharepoint solution on BPOS. A critical issue was found in the prodution version. On dev side we already have progressed to the next version, currently wating for it to be deployed on production.</p>
<p>Also our test environments contained the latest version. To test the issue we need to revert back to the older version. Considering the complexity of the solution this meant hours of rollback effort which we could not afford considering the criticality of the issue. Luckily we had Hyper-V snapshots to our rescue. The effort of many hours got tranformed into a 10 min task by restoring the snapshots. </p>
<p>I have seen many other instances of Hyper-V like speeding up builds and automated daily deployments (deployments which are meant for testing deployment scripts and need to be run on clean slate every time)</p>
<p>I really consider Hyper-V to be a must have for Sharepoint environments atleast Dev and QA.</p>]]></content:encoded>
    </item>
    <item>
      <title>Lookup field across sites</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/lookup-field-across-sites</link>
      <pubDate>Sat, 18 Dec 2010 23:04:59 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2010/12/18/lookup-field-across-sites/</guid>
      <description><![CDATA[Came across this really useful blog from Sahil...]]></description>
      <content:encoded><![CDATA[<p>Came across this really useful blog from Sahil Malik.</p>
<p><a href="http://blah.winsmarts.com/2009-3-Using_Site_Lookup_columns,_across_sites.aspx">http://blah.winsmarts.com/2009-3-Using_Site_Lookup_columns,_across_sites.aspx</a></p>
<p><br />This one shows how we can use a lookup field across the sites. Though this will work only for top down hierarchy i.e. you can have a look up column in child site that looks up a list in the parent. Not the other way.</p>
<p>If you want to have it the other way i believe custom field type will be the way to go.</p>]]></content:encoded>
    </item>
    <item>
      <title>Modifying Sharepoint Application Pages in the RIGHT WAY</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/modifying-sharepoint-application-pages-in-the-right-way</link>
      <pubDate>Sat, 18 Dec 2010 05:02:00 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2010/12/18/modifying-sharepoint-application-pages-in-the-right-way/</guid>
      <description><![CDATA[So many time we come across scenarios where we need to modify the functionality Sharepoint...]]></description>
      <content:encoded><![CDATA[<p>So many time we come across scenarios where we need to modify the functionality Sharepoint Application Pages (for those who are new to sharepoint Application Pages are physical asp.net pages residing the Layouts folder)</p>
<p>Microsoft recommendation is not to modify these as the modifications can get overwritten in the next service pack or a patch. So what do you do when you want to modify the functionality of a Sharepoint Application Page. For example we had a scenario where we wanted to prevent users from entering 'NT Authority\All Authenticated Users' in the "People and Groups". This is the "aclinv.aspx" application page.</p>
<p><img src="file:///C:/Users/sasohail/AppData/Local/Temp/moz-screenshot.png" /><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/2022.peopleNgroups.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-79/2022.peopleNgroups.jpg" border="0" /></p>
<p>One of the solution is to make the copy of a page and then modify it. It looks good at first but with a bit more of investigation one will realize that it has potential for more bugs because it means rewriting functionality that has already existed and is certainly well tested. The other solution i am going to present here will demonstrate the power and flexibility of the asp.net framework.&nbsp; This solution involves creating a HTTPModule which will modify the control tree of the page to achieve the required functionality.</p>
<p>Lets look at the scenario i mentioned above where i want to add custom validation to prevent giving permissions to 'NT Authority\All Authenticated Users'. The following summarizes the steps needed to be performed to achieve this</p>
<p>1. Create a custom HTTPModule and bind it to the desired sharepoint web application.<br />2. In the custom http module check if the page is "aclinv.aspx". Catch the init event of the page.<br />3. In the init event of the page add a custom validator.<br />4. Perform the validation in the ServerValidate event of the custom validator.</p>
<p>Let me demonstrate with more details</p>
<p>Create a new class and inherit it from the IHTTPModule class. Override the init and dispose method. Catch the PreRequestHandlerExecute event of the HttpApplication class.&nbsp; This event is triggered just before the page execution starts.</p>
<p>&nbsp; &nbsp; &nbsp;&nbsp;<b>&nbsp; public void Init(HttpApplication context)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b><br />In the PreRequestHandlerExecute event attach to the Init event of the Page class as shown below</p>
<p><b>&nbsp;void context_PreRequestHandlerExecute(object sender, EventArgs e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpApplication httpApp = sender as HttpApplication;<br /><br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (httpApp != null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page = httpApp.Context.CurrentHandler as Page;<br /><br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (page != null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("_layouts/aclinv.aspx"))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page.Init += new EventHandler(page_Init);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b></p>
<p>&nbsp;</p>
<p>Looks simple enough. Now we just need to add a custom validator control to the page. I want the custom validator control to be displayed just below the "Add Users" field. To figure out the location i opened the "aclinv.aspx" page in the Layouts folder. You can see that the Add Users field is a PeopleEditor control</p>
<p><b><br /></b></p>
<p><b>&lt;asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"&gt;<br />&lt;TABLE border="0" cellspacing="0" cellpadding="0" class="ms-propertysheet"&gt;<br />&nbsp;&nbsp;&nbsp; &lt;wssuc:InputFormSection Title="&lt;%$Resources:wss,aclinv_Step1Title%&gt;"<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Description="&lt;%$Resources:wss,aclinv_DescGrantIndiv%&gt;"<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; runat="server"&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Template_Description&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;SharePoint:EncodedLiteral runat="server" text="&lt;%$Resources:wss,aclinv_DescGrantIndiv%&gt;" EncodeMethod='HtmlEncode'/&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;br&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;br&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;asp:LinkButton id="LinkAddAuthUsers" Text="&lt;%$Resources:wss,permsetup_addauthtitle%&gt;" runat="server"<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; CausesValidation="false" OnClick="LinkAddAuthUsers_Click" /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/Template_Description&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Template_InputFormControls&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;wssuc:InputFormControl LabelText="&lt;%$Resources:wss,aclinv_UserGroupsLabel%&gt;" runat="server"&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;Template_Control&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;wssawc:PeopleEditor<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AllowEmpty=false<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ValidatorEnabled="true"<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; id="userPicker"<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; runat="server"<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ShowCreateButtonInActiveDirectoryAccountCreationMode=true<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SelectionSet="User,SecGroup,SPGroup"<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/Template_Control&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/wssuc:InputFormControl&gt;<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/Template_InputFormControls&gt;<br />&nbsp;&nbsp;&nbsp; &lt;/wssuc:InputFormSection&gt;</b></p>
<p>This is nested in a deep hierarchy of controls and we need to play around to figure out the exact location where we can add the controls. I temporarily&nbsp;added the following bit of code to the httpModule to display the entire control hierarchy of the page.</p>
<p><b>private string GetControlCollection(Control ctrl, string indent)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str = string.Empty;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (Control child in ctrl.Controls)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str += "&lt;br&gt;" + indent + child.GetType().Name + " -- " + child.ID;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (child.Controls.Count &gt; 0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str += GetControlCollection(child, indent + "&amp;nbsp;&amp;nbsp;&amp;nbsp;");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return str;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b></p>
<p>I called this function in the page_Init event in the custom HttpModule.</p>
<p><b>string hierarchy = GetControlCollection(page);<br />Literal literal = new Literal(){ Text= hierarchy};<br />page.Controls.Add(literal);</b></p>
<p>This displayed the entire control hierarchy of the page. Looking at it we can figure out the location of the "Add Users " control which can be accessed using the following code -</p>
<p><strong>Control ctrl = page.Form.FindControl("PlaceHolderMain").Controls[1].FindControl("PlaceHolderControls").Controls[1].FindControl("PlaceHolderControl").FindControl("userPicker");</strong></p>
<p>Thats it we are almost done. Just need to add the custom validator and handle the ServerValidate event of it.</p>
<p>The code will look something like this.</p>
<p>In the page_Init</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<b> Control ctrl = page.Form.FindControl("PlaceHolderMain").Controls[1].FindControl("PlaceHolderControls").Controls[1]. FindControl("PlaceHolderControl").FindControl("userPicker"); //get reference to the "Add User"s control<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomValidator cust1 = new CustomValidator();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cust1.ServerValidate += new ServerValidateEventHandler(cust1_ServerValidate); // Handle the event to perform validation<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cust1.ControlToValidate = "userPicker";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cust1.Text = "'NT Authority\\All Authenticated Users' is disabled and cannot be added to any group. Please contact your system administrator"; //set the error message to be displayed if the validation fails<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctrl.Parent.Controls.AddAt(ctrl.Parent.Controls.IndexOf(ctrl) + 1, cust1); //add the custom validator just after the Add Users control</b></p>
<p>In the cust1_ServerValidate</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <b>string[] arr = args.Value.Split(',');<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (string str in arr)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (string.Compare(str, "nt authority\\authenticated users", StringComparison.InvariantCultureIgnoreCase) == 0) //user entered "NT Authority\Authenticated Users" as one of the options<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; args.IsValid = false; //fail the validation<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</b></p>
<p>The following is the complete code for the HttpModule</p>
<p>&nbsp;</p>
<p><b>using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Text;<br />using System.Web;<br />using System.Web.UI;<br />using System.Web.UI.WebControls;<br />using Microsoft.SharePoint.WebControls;<br /><br />namespace poc_httpmodule<br />{<br />&nbsp;&nbsp;&nbsp; public class ValidatorModule : IHttpModule<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Page page;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void Init(HttpApplication context)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; context.PreRequestHandlerExecute += new EventHandler(context_PreRequestHandlerExecute);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void context_PreRequestHandlerExecute(object sender, EventArgs e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpApplication httpApp = sender as HttpApplication;<br /><br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (httpApp != null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page = httpApp.Context.CurrentHandler as Page;<br /><br /><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (page != null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("_layouts/aclinv.aspx"))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; page.Init += new EventHandler(page_Init);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void page_Init(object sender, EventArgs e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (page != null)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Control ctrl = page.Form.FindControl("PlaceHolderMain").Controls[1].FindControl("PlaceHolderControls"). Controls[1]. FindControl("PlaceHolderControl").FindControl("userPicker"); //get reference to the "Add User"s control<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CustomValidator cust1 = new CustomValidator();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cust1.ServerValidate += new ServerValidateEventHandler(cust1_ServerValidate); // Handle the event to perform validation<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cust1.ControlToValidate = "userPicker";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cust1.Text = "'NT Authority\\All Authenticated Users' is disabled and cannot be added to any group. Please contact your system administrator"; //set the error message to be displayed if the validation fails<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctrl.Parent.Controls.AddAt(ctrl.Parent.Controls.IndexOf(ctrl) + 1, cust1); //add the custom validator just after the Add Users control<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void cust1_ServerValidate(object source, ServerValidateEventArgs args)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] arr = args.Value.Split(',');<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (string str in arr)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (string.Compare(str, "nt authority\\authenticated users", StringComparison.InvariantCultureIgnoreCase) == 0) //user entered "NT Authority\Authenticated Users" as one of the options<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; args.IsValid = false; //fail the validation<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void Dispose()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; }<br />}</b></p>
<p>Last step is to plug in our HttpModule. Add a strong name to the project and add the dll to the gac. Add the following in the &lt;httpModules&gt; tag.&nbsp; Replace the "Public Key Token" to the appropriate value</p>
<p>&lt;add name="ValidatorModule" type="poc_httpmodule.ValidatorModule, poc_httpmodule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<span style="background-color: #ffff00;"><b>7f1d0bb0d60d5701</b></span>" /&gt;</p>
<p>Now browse to the intended sharepoint site and try to add "NT Authority\Authenticated Users".&nbsp; You should see the following message </p>
<p><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/29/79/5635.validation.jpg" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-01-29-79/5635.validation.jpg" border="0" /></p>
<p>Seems amazing doesn't it. One really cannot help thinking of the amazing things that can be achieved using the power of asp.net. If you thought sharepoint puts too many restrictions compared to asp.net think again :-).</p>
<p>&nbsp;</p>
<p><b>Happy Programming<br />Sohail</b></p>]]></content:encoded>
    </item>
    <item>
      <title>Access denied within SPSecurity.RunWithElevatedPrivileges</title>
      <link>https://docs.microsoft.com/archive/blogs/sasohail/access-denied-within-spsecurity-runwithelevatedprivileges</link>
      <pubDate>Sun, 31 Oct 2010 09:47:00 GMT</pubDate>
      <dc:creator><![CDATA[Sohail Sayed]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/sasohail/2010/10/31/access-denied-within-spsecurity-runwithelevatedprivileges/</guid>
      <description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; Learned something really interesting (and a few lessons)&nbsp;in the last...]]></description>
      <content:encoded><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp; Learned something really interesting (and a few lessons)&nbsp;in the last few days. We were doing an operation within a webpart which required higher level of access. Since this was to be executed irrespective of the access of the user logged in, we had the code enclosed within the SPSecurity.RunWithElevatedPrivileges. Surprisingly the code was failing and showing "Error : Access Denied". I remembered having seen this issue earlier on another project.&nbsp;That time we had a workaround which looked elegant and we didn't need to investigate the root cause. But now&nbsp;things&nbsp;were not as&nbsp;good and&nbsp;made me think&nbsp;this was going to be a bummer.&nbsp; Luckily&nbsp;I was able to figure it out&nbsp;in time.&nbsp; Let me explain this with the below code that throws access denied even though it is wrapped within the SPSecurity.RunWithElevatedPrivileges.</p>
<p>The code is part of a webpart that just displayed all the users in the owners group of the current site.&nbsp; This code runs fine with users having Full control or Contribute access. But fails for users having only Read access.<span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: x-small">&nbsp; </span></span></span></span></span></span></p>
<p><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; COLOR: #2b91af; FONT-SIZE: x-small"></span></span></span></span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Arial;">Label&nbsp; </span>labelUsers;<span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;&nbsp;</span></span></span></span></p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">protected</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">override</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">void</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> CreateChildControls() </span></span>{</p>
<p>&nbsp;labelUsers =&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">Label</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">();<span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;</span></span></span><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;</span></span>&nbsp;</p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">this</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.Controls.Add(labelUsers);<span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;</span></span></span><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;</span></span></p>
<p><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPSecurity</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.RunWithElevatedPrivileges(</span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">delegate</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">() {<span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"> </span></span></span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;&nbsp; </span></span></span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPSite</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> site = </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPContext</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.Current.Site;<span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp; </span></span></span></span>&nbsp;</p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp; &nbsp;</span></span></span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPWeb</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> web = </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPContext</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.Current.Web;<span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;&nbsp;</span></span></span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;&nbsp; </span></span></span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPGroup</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> group = web.Groups.GetByID(3);</span></span><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;">//get the owners group</span></span></span></p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp; if</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (group != </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">null</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">) {</span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">StringBuilder</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> users = </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">StringBuilder</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">();<span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;&nbsp;</span></span></span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">for</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (</span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">int</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> cnt = 0; cnt &lt; group.Users.Count; cnt++) {&nbsp;</span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;&nbsp;</span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>&nbsp;&nbsp;&nbsp;&nbsp; users.AppendFormat(<span style="font-family: Consolas; color: #a31515; font-size: x-small;"><span style="font-family: Consolas; color: #a31515; font-size: x-small;"><span style="font-family: Consolas; color: #a31515; font-size: x-small;">"{0},"</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">, group.Users[cnt]);</span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>&nbsp;&nbsp; }</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small"><span style="FONT-FAMILY: Consolas; FONT-SIZE: x-small">labelUsers.Text = users.ToString();</span></span><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;">//display it on the label</span></span></span>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;">//End of "If" block</span></span></span>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });<span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;">//Close "SPSecurity.RunWithElevatedPrivileges" block</span></span></span></p>
<p>&nbsp;}</p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span>
<p>&nbsp;&nbsp;This code throws an exception for Read users at the line "<span style="font-size: x-small;"><span style="font-family: Consolas; color: #0000ff;"><span style="font-family: Consolas; color: #0000ff;"><span style="font-family: Consolas; color: #0000ff;">for</span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> (</span></span><span style="font-family: Consolas; color: #0000ff;"><span style="font-family: Consolas; color: #0000ff;"><span style="font-family: Consolas; color: #0000ff;">int</span></span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"><span style="font-size: x-small;"> cnt = 0; cnt &lt; group.Users.Count; cnt++)". </span></span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"><span style="font-size: x-small;"><span style="font-family: Arial;">This&nbsp;line fails when the Users collection withing the SPGroup it being accessed.</span></span><span style="font-family: Consolas;"><span style="font-family: Consolas;"> </span></span></span></span></p>
<p><span style="font-family: Consolas;"><span style="font-family: Consolas;"><span style="font-family: Consolas;"><span style="font-family: Consolas;"></span></span></span></span>Looks like&nbsp;the SPSecurity class is&nbsp;not&nbsp;behaving&nbsp;correctly here but lt is working perfectly in the way it is supposed to.Though the entire code is enclosed within SPSecurity.RunWithElevatedPrivileges not all code is able to run with the elevated privileges. So the rule is&nbsp;--&nbsp; The code will not run within elevated privilege if the object accessed was not created within the SPSecurity.RunWithElevatedPrivileges block. If we take a relook at the code we can see that the instances of&nbsp;SPSite (i.e. site object )&nbsp;and SPWeb (i.e. web object) are retrieved through the current SPContext. The SPContext is created much before our elevated privilege code runs. Accessing the&nbsp;child objects of the SPWeb instance in form of "<span style="font-family: Consolas; font-size: x-small;">web.Groups.GetByID(3)" </span>returns a SPGroup object which will also fail to run within the elevated privilege. And once&nbsp;we (with only read access)&nbsp;try to access the Users collection within the SPGroup object Sharepoint rings the bell indicating&nbsp;the information is classified. It&nbsp;throws you out of execution by rasing an exception. </p>
</p>
<p>&nbsp;</p>
<p>
<p>&nbsp;&nbsp;&nbsp; Now that&nbsp;we know the reason for the error, the problem doesn't look too tough and in reality the solution is simple. To run this code successully we need to&nbsp;create the SPSite and SPWeb instances within the SPSecurity.RunWithElevatedPrivileges. So we have the new code below (the changes are highlighted)</p>
<p>&nbsp;<span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">Label</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> labelUsers; </span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">protected</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">override</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">void</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> CreateChildControls(){ </span></span></p>
</p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Arial; color: #000000;">labelUsers =&nbsp;&nbsp;</span>new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">Label</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">();<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span></span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">this</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.Controls.Add(labelUsers); </span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPSecurity</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.RunWithElevatedPrivileges(</span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">delegate</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">(){&nbsp;<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">&nbsp; </span></span></span></p>
<p><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span>SPSite</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> site = </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPContext</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.Current.Site;&nbsp;<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">&nbsp;&nbsp;</span></span></span></p>
<p><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span>SPWeb</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> web = </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">SPContext</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">.Current.Web;&nbsp;<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;</span></span></span></p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span></span></span><span style="background-color: #ffff00;">&nbsp;using</span></span></span></span><span style="background-color: #ffff00;"><span style="font-size: x-small;"><span style="font-size: x-small;"> (</span></span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">SPSite</span></span></span><span style="font-size: x-small;"><span style="font-size: x-small;"> newSite = </span></span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">new</span></span></span><span style="font-size: x-small;"><span style="font-size: x-small;"> </span></span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">SPSite</span></span></span></span><span style="font-size: x-small;"><span style="font-size: x-small;"><span style="background-color: #ffff00;">(site.ID)) {&nbsp;</span><span style="font-size: x-small;"><span style="font-size: x-small;"></span></span></span></span><span style="background-color: #ffff00;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">&nbsp; </span></span></span></span></p>
<p><span style="background-color: #ffff00;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span></span></span></span>using</span></span></span><span style="font-size: x-small;"><span style="font-size: x-small;"> (</span></span><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;"><span style="color: #2b91af; font-size: x-small;">SPWeb</span></span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"><span style="background-color: #ffff00;"> newWeb = newSite.OpenWeb(web.ID)){</span> <span style="color: #008000;">//Do not use the site object to create the SPWeb instance else the code will still fail</span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;</span></span></span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></p>
<p><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span></span></span></span></span></span></span>SPGroup</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> group = <span style="background-color: #ffff00;">newWeb</span>.Groups.GetByID(3);</span></span><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;">&nbsp; //get the owners group</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span></span></span></span></span></span></span>if</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (group != </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">null</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">) {&nbsp;&nbsp;</span></span>&nbsp;</p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> <span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">StringBuilder </span></span></span>users = </span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">new</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> </span></span><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;"><span style="font-family: Consolas; color: #2b91af; font-size: x-small;">StringBuilder</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">();<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"></span></span></span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>for</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;"> (</span></span><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">int </span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">cnt = 0; cnt &lt; group.Users.Count; cnt++) {<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;</span></span></span></span>&nbsp;</p>
<p><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;"><span style="font-family: Consolas; color: #0000ff; font-size: x-small;">&nbsp;&nbsp;&nbsp; </span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>users.AppendFormat(<span style="font-family: Consolas; color: #a31515; font-size: x-small;"><span style="font-family: Consolas; color: #a31515; font-size: x-small;"><span style="font-family: Consolas; color: #a31515; font-size: x-small;">"{0},"</span></span></span><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">, group.Users[cnt]);</span></span></p>
<p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; labelUsers.Text = users.ToString(); </p>
</span></span></span></span><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;"><span style="font-family: Consolas; color: #008000; font-size: x-small;">//display it on the label</span></span></span></p>
<p><span style="font-family: Consolas; font-size: x-small;"><span style="font-family: Consolas; font-size: x-small;">
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; }<span style="color: #008000;">// End of "If" block</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<span style="color: #008000;">// End of using for SPWeb</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;}<span style="color: #008000;">// End of Using for SPSite</span></p>
<p>&nbsp;&nbsp; });<span style="color: #008000;">//End of SPSecurity.RunWithElevatedPrivileges</span>&nbsp;</p>
<p>}</p>
</span></span></p>
<p>&nbsp;This code now works beautifully.</p>
<p>With some more space to write let me jot down the lessons learned &nbsp;(little bits of wisdom we cannot afford to ignore ;-) )</p>
<p>Lesson 1 - &nbsp;Just putting&nbsp;your code within SPSecurity.RunWithElevatedPrivileges does not guarantee your code to run successfully irrespective of the access of the user logged in. You may want to look at the code carefully when writing it and look back at&nbsp;it again once you have written thinking that it will work fine no matter what.</p>
</p>
<p>Lesson 2 - No matter how confident you are with your code, its always better&nbsp;in sharepoint&nbsp;to unit test your code with all three types of user access (i.e. Owner/Full control&nbsp;access, Members/Contribute access and Read/Visitor access). I have made it a point to write my unit tests with all the three types user access in consideration and hopefully will be able to avoid similar mistakes in future.</p>
<p>Lesson 3 - And the final one. As one of&nbsp;my friend says "the world is round". So things we ignore (or maybe just use some workarounds no matter how elegant) do come back to us :-). In software it always pays to get to the root of the problem even if there is a workaround to the problem.&nbsp;&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>