<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mylifeinaminute.com &#187; C#</title>
	<atom:link href="http://www.mylifeinaminute.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mylifeinaminute.com</link>
	<description>You can learn a lot in a minute</description>
	<lastBuildDate>Wed, 18 Jan 2012 02:33:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Fixing Absolute URLs in a Content Editor Web Part</title>
		<link>http://www.mylifeinaminute.com/2008/12/24/fixing-absolute-urls-in-a-content-editor-web-part/</link>
		<comments>http://www.mylifeinaminute.com/2008/12/24/fixing-absolute-urls-in-a-content-editor-web-part/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 15:00:24 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Sharepoint Server]]></category>
		<category><![CDATA[TechNet]]></category>
		<category><![CDATA[Windows SharePoint Services]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[control adapter]]></category>
		<category><![CDATA[moss 2007]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.mylifeinaminute.com/?p=271</guid>
		<description><![CDATA[Maxime Bombardier has a post on the subject of fixing one of the bigger issues with the Content Editor web part. For the uninitiated, a Content Editor web part always renders absolute URLs when the rich-text editing capabilities are used. I must admit that I would have never have thought to use a control adapter [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blogs.msdn.com/maximeb/default.aspx" title="Maxime Bombardier">Maxime Bombardier</a> has a post on the subject of fixing one of the bigger issues with the Content Editor web part. For the uninitiated, a <a href="http://www.contenteditorwebpart.com/default.aspx">Content Editor web part</a> always renders absolute URLs when the rich-text editing capabilities are used. I must admit that I would have never have thought to use a <a href="http://msdn.microsoft.com/en-us/library/67276kc5.aspx" title="Architectural Overview of Adaptive Control Behavior">control adapter</a> to manipulate the output of the web part on the fly. Now that I have learned something new, you should too.</p>
</p>
<p><a href="http://blogs.msdn.com/maximeb/archive/2008/12/23/fixing-absolute-urls-for-all-alternate-access-mappings-aam-of-content-editor-web-part-with-a-control-adapter.aspx" title="Fixing absolute URLs for all Alternate Access Mappings (AAM) of Content Editor Web Part with a Control Adapter">Go check it out</a>.</p>
<p><map name='google_ad_map_271_0feb153b14d1a0fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/271?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_271_0feb153b14d1a0fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=271&amp;url= http%3A%2F%2Fwww.mylifeinaminute.com%2F2008%2F12%2F24%2Ffixing-absolute-urls-in-a-content-editor-web-part%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.mylifeinaminute.com/2008/12/24/fixing-absolute-urls-in-a-content-editor-web-part/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HubKey&#8217;s Development Hole</title>
		<link>http://www.mylifeinaminute.com/2008/12/23/hubkeys-development-hole/</link>
		<comments>http://www.mylifeinaminute.com/2008/12/23/hubkeys-development-hole/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 21:08:35 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Sharepoint Server]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Windows SharePoint Services]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[hubkey]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.mylifeinaminute.com/?p=262</guid>
		<description><![CDATA[Over at the Development Hole, the HubKey crew has been busy building out a SharePoint API that mimics the internal SharePoint object model. If you have ever felt the pain of having to have a SharePoint instance/farm/installation available to run your code again, you&#8217;ll appreciate what HubKey is doing. You can grab a beta of [...]]]></description>
			<content:encoded><![CDATA[<p>Over at the <a href="http://geek.hubkey.com" title="Development Hole">Development Hole</a>, the <a href="http://www.hubkey.com/" title="HubKey">HubKey</a> crew has been busy building out a <a href="http://geek.hubkey.com/2008/11/sharepoint-api-client-side-object-model.html" title="SharePoint API: A client-side object model">SharePoint API</a> that mimics the internal SharePoint object model.</p>
<p>If you have ever felt the pain of having to have a SharePoint instance/farm/installation available to run your code again, you&#8217;ll appreciate what <a href="http://www.hubkey.com/" title="HubKey">HubKey</a> is doing.  You can grab a beta of their API <a href="http://www.hubkey.com/contact.aspx">here</a> (select HubKey SharePoint API as your interest).</p>
<p><map name='google_ad_map_262_0feb153b14d1a0fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/262?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_262_0feb153b14d1a0fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=262&amp;url= http%3A%2F%2Fwww.mylifeinaminute.com%2F2008%2F12%2F23%2Fhubkeys-development-hole%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.mylifeinaminute.com/2008/12/23/hubkeys-development-hole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating User Profile Properties for the Current User</title>
		<link>http://www.mylifeinaminute.com/2008/12/16/updating-user-profile-properties-for-the-current-user/</link>
		<comments>http://www.mylifeinaminute.com/2008/12/16/updating-user-profile-properties-for-the-current-user/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 16:46:48 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Sharepoint Server]]></category>
		<category><![CDATA[TechNet]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Windows SharePoint Services]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[moss 2007]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint Profile Management]]></category>

		<guid isPermaLink="false">http://www.mylifeinaminute.com/?p=256</guid>
		<description><![CDATA[Updates to a user&#8217;s profile properties can be performed with the following:]]></description>
			<content:encoded><![CDATA[<p>Updates to a user&#8217;s profile properties can be performed with the following:</p>
<p><span id="more-256"></span></p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
SPSite site = SPContext.GetContext(HttpContext.Current).Site;
                ServerContext serverContext = ServerContext.GetContext(site);

                UserProfileManager profileManager = new UserProfileManager(serverContext);
                UserProfile currentUserProfile = profileManager.GetUserProfile(System.Web.HttpContext.Current.User.Identity.Name);

                if (this.chkTerms.Checked)
                    currentUserProfile[&quot;TermsOfUseAccepted&quot;].Value = &quot;true&quot;;
                else
                    currentUserProfile[&quot;TermsOfUseAccepted&quot;].Value = &quot;false&quot;;

                currentUserProfile[&quot;SecurityQuestion1&quot;].Value = this.lstQuestion1.SelectedItem.Text + &quot;|&quot; + Server.HtmlEncode(this.txtQuestion1Ans.Text);
                currentUserProfile[&quot;SecurityQuestion2&quot;].Value = this.lstQuestion2.SelectedItem.Text + &quot;|&quot; + Server.HtmlEncode(this.txtQuestion2Ans.Text);
                currentUserProfile[&quot;SecurityQuestion3&quot;].Value = this.lstQuestion3.SelectedItem.Text + &quot;|&quot; + Server.HtmlEncode(this.txtQuestion3Ans.Text);

                currentUserProfile.Commit();

                site.RootWeb.Dispose();
                site.Dispose();
</pre>
</pre>
<p><map name='google_ad_map_256_0feb153b14d1a0fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/256?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_256_0feb153b14d1a0fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=256&amp;url= http%3A%2F%2Fwww.mylifeinaminute.com%2F2008%2F12%2F16%2Fupdating-user-profile-properties-for-the-current-user%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.mylifeinaminute.com/2008/12/16/updating-user-profile-properties-for-the-current-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retrieving User Profile Properties for the Current User</title>
		<link>http://www.mylifeinaminute.com/2008/12/16/retrieving-user-profile-properties-for-the-current-user/</link>
		<comments>http://www.mylifeinaminute.com/2008/12/16/retrieving-user-profile-properties-for-the-current-user/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 16:42:10 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Sharepoint Server]]></category>
		<category><![CDATA[TechNet]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Windows SharePoint Services]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[moss 2007]]></category>
		<category><![CDATA[Shared Services Provider]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint Profile Management]]></category>
		<category><![CDATA[SharePoint User Management]]></category>

		<guid isPermaLink="false">http://www.mylifeinaminute.com/?p=254</guid>
		<description><![CDATA[Retrieving a user&#8217;s profile properties can be achieved with the following block: Note that this buids on Creating Custom Profile Properties Through Code.]]></description>
			<content:encoded><![CDATA[<p>Retrieving a user&#8217;s profile properties can be achieved with the following block:</p>
<p><span id="more-254"></span></p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
SPSite site = SPContext.GetContext(HttpContext.Current).Site;
            ServerContext serverContext = ServerContext.GetContext(site);

            UserProfileManager profileManager = new UserProfileManager(serverContext);
            UserProfile currentUserProfile = null;

            if (profileManager.UserExists(System.Web.HttpContext.Current.User.Identity.Name))
                currentUserProfile = profileManager.GetUserProfile(System.Web.HttpContext.Current.User.Identity.Name);
            else
                currentUserProfile = profileManager.CreateUserProfile(System.Web.HttpContext.Current.User.Identity.Name);

            string termsOfUseAnswered = (string)currentUserProfile[&quot;TermsOfUseAccepted&quot;].Value;
            string securityQuestion1 = (string)currentUserProfile[&quot;SecurityQuestion1&quot;].Value;
            string securityQuestion2 = (string)currentUserProfile[&quot;SecurityQuestion2&quot;].Value;
            string securityQuestion3 = (string)currentUserProfile[&quot;SecurityQuestion3&quot;].Value;
</pre>
</pre>
<p>Note that this buids on <a href="/2008/12/16/creating-custom-profile-properties-through-code-c/" title="Creating Custom Profile Properties Through Code (C#)">Creating Custom Profile Properties Through Code</a>.</p>
<p><map name='google_ad_map_254_0feb153b14d1a0fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/254?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_254_0feb153b14d1a0fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=254&amp;url= http%3A%2F%2Fwww.mylifeinaminute.com%2F2008%2F12%2F16%2Fretrieving-user-profile-properties-for-the-current-user%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.mylifeinaminute.com/2008/12/16/retrieving-user-profile-properties-for-the-current-user/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Custom Profile Properties through Code (C#)</title>
		<link>http://www.mylifeinaminute.com/2008/12/16/creating-custom-profile-properties-through-code-c/</link>
		<comments>http://www.mylifeinaminute.com/2008/12/16/creating-custom-profile-properties-through-code-c/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 16:27:21 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Sharepoint Server]]></category>
		<category><![CDATA[TechNet]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Windows SharePoint Services]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[moss 2007]]></category>
		<category><![CDATA[Shared Services Provider]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint Profile Management]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.mylifeinaminute.com/?p=248</guid>
		<description><![CDATA[I recently needed to add several custom profile properties through a web part for tracking a users&#8217; security preferences for a particular web application. The following is the method used to create four new properties in the SSP: Note that the current context (HttpContext.Current) needs to be saved off, set to null, then reinstated upon [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to add several custom profile properties through a web part for tracking a users&#8217; security preferences for a particular web application.</p>
<p>The following is the method used to create four new properties in the SSP:</p>
<p><span id="more-248"></span></p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
private void VerifyCreateBaseProfileProperties()
        {
            SPSite site = SPContext.GetContext(HttpContext.Current).Site;
            Guid siteId = site.ID;
            HttpContext savedContext = HttpContext.Current;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite elevatedSite = new SPSite(siteId))
                {
                    try
                    {
                        HttpContext.Current = null;

                        elevatedSite.AllowUnsafeUpdates = true;
                        elevatedSite.RootWeb.AllowUnsafeUpdates = true;

                        ServerContext serverContext = ServerContext.GetContext(elevatedSite);

                        UserProfileManager profileManager = new UserProfileManager(serverContext);
                        UserProfileConfigManager profileConfigManager = new UserProfileConfigManager(serverContext);
                        PropertyCollection propertyCollection = profileConfigManager.GetProperties();

                        bool question1Exists = false;
                        bool question2Exists = false;
                        bool question3Exists = false;
                        bool termsOfUseExists = false;

                        foreach (Property property in profileManager.Properties)
                        {
                            switch (property.Name)
                            {
                                case &quot;SecurityQuestion1&quot;:
                                    question1Exists = true;
                                    break;
                                case &quot;SecurityQuestion2&quot;:
                                    question2Exists = true;
                                    break;
                                case &quot;SecurityQuestion3&quot;:
                                    question3Exists = true;
                                    break;
                                case &quot;TermsOfUseAccepted&quot;:
                                    termsOfUseExists = true;
                                    break;
                            }
                        }

                        if (!question1Exists)
                        {
                            Property question1 = propertyCollection.Create(false);
                            question1.Name = &quot;SecurityQuestion1&quot;;
                            question1.DisplayName = &quot;Security Question 1&quot;;
                            question1.Type = &quot;string&quot;;
                            question1.PrivacyPolicy = PrivacyPolicy.OptIn;
                            question1.DefaultPrivacy = Privacy.Private;
                            question1.Description = &quot;Security Question 1&quot;;
                            question1.IsSearchable = false;
                            question1.IsVisibleOnEditor = false;
                            question1.IsAlias = false;
                            question1.Length = 100;
                            question1.IsUserEditable = true;
                            propertyCollection.Add(question1);
                        }
                        if (!question2Exists)
                        {
                            Property question2 = propertyCollection.Create(false);
                            question2.Name = &quot;SecurityQuestion2&quot;;
                            question2.DisplayName = &quot;Security Question 2&quot;;
                            question2.Type = &quot;string&quot;;
                            question2.PrivacyPolicy = PrivacyPolicy.OptIn;
                            question2.DefaultPrivacy = Privacy.Private;
                            question2.Description = &quot;Security Question 2&quot;;
                            question2.IsSearchable = false;
                            question2.IsVisibleOnEditor = false;
                            question2.IsAlias = false;
                            question2.Length = 100;
                            question2.IsUserEditable = true;
                            propertyCollection.Add(question2);
                        }
                        if (!question3Exists)
                        {
                            Property question3 = propertyCollection.Create(false);
                            question3.Name = &quot;SecurityQuestion3&quot;;
                            question3.DisplayName = &quot;Security Question 3&quot;;
                            question3.Type = &quot;string&quot;;
                            question3.PrivacyPolicy = PrivacyPolicy.OptIn;
                            question3.DefaultPrivacy = Privacy.Private;
                            question3.Description = &quot;Security Question 3&quot;;
                            question3.IsSearchable = false;
                            question3.IsVisibleOnEditor = false;
                            question3.IsAlias = false;
                            question3.Length = 100;
                            question3.IsUserEditable = true;
                            propertyCollection.Add(question3);
                        }
                        if (!termsOfUseExists)
                        {
                            Property termsofUsequestion = propertyCollection.Create(false);
                            termsofUsequestion.Name = &quot;TermsOfUseAccepted&quot;;
                            termsofUsequestion.DisplayName = &quot;Terms Of Use Accepted&quot;;
                            termsofUsequestion.Type = &quot;string&quot;;
                            termsofUsequestion.PrivacyPolicy = PrivacyPolicy.OptIn;
                            termsofUsequestion.DefaultPrivacy = Privacy.Private;
                            termsofUsequestion.Description = &quot;Terms Of Use Accepted&quot;;
                            termsofUsequestion.IsSearchable = false;
                            termsofUsequestion.IsVisibleOnEditor = false;
                            termsofUsequestion.IsAlias = false;
                            termsofUsequestion.Length = 10;
                            termsofUsequestion.IsUserEditable = true;
                            propertyCollection.Add(termsofUsequestion);
                        }
                    }
                    catch (Exception exc)
                    {
                    }
                    finally
                    {
                        elevatedSite.Dispose();
                    }
                }
            });

            site.Dispose();
            HttpContext.Current = savedContext;
        }
</pre>
</pre>
<p>Note that the current context (HttpContext.Current) needs to be saved off, set to null, then reinstated upon the completion of the method.</p>
<p><map name='google_ad_map_248_0feb153b14d1a0fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/248?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_248_0feb153b14d1a0fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=248&amp;url= http%3A%2F%2Fwww.mylifeinaminute.com%2F2008%2F12%2F16%2Fcreating-custom-profile-properties-through-code-c%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.mylifeinaminute.com/2008/12/16/creating-custom-profile-properties-through-code-c/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Custom Method for Checking Permissions on a SPWeb Object</title>
		<link>http://www.mylifeinaminute.com/2008/11/21/custom-method-for-checking-permissions-on-a-spweb-object/</link>
		<comments>http://www.mylifeinaminute.com/2008/11/21/custom-method-for-checking-permissions-on-a-spweb-object/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 14:24:20 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Sharepoint Server]]></category>
		<category><![CDATA[TechNet]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Windows SharePoint Services]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[moss 2007]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SPBasePermissions]]></category>

		<guid isPermaLink="false">http://www.mylifeinaminute.com/?p=189</guid>
		<description><![CDATA[The out-of-the-box method DoesUserHavePermissions() on an SPWeb object does not take indirect membership into account (i.e. the current user is a member of a domain group that has access the the SPWeb being checked).  To get around this, I use the following method (DoesUserHavePermssionsToWeb(SPUser, SPWeb)): Note that in the above method is checking for SPBasePermissions [...]]]></description>
			<content:encoded><![CDATA[<p>The out-of-the-box method <a title="DoesUserHavePermissions Method" href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.doesuserhavepermissions.aspx">DoesUserHavePermissions()</a> on an SPWeb object does not take indirect membership into account (i.e. the current user is a member of a domain group that has access the the SPWeb being checked).  To get around this, I use the following method (<strong>DoesUserHavePermssionsToWeb(SPUser, SPWeb)</strong>):</p>
<p><span id="more-189"></span></p>
<pre>
<pre class="brush: csharp; title: ; notranslate">
        private bool DoesUserHavePermssionsToWeb(ref SPUser user, ref SPWeb web)
        {
            bool hasPermission = false;

            SPBasePermissions perms = this.GetPermissionsForUser(ref user, ref web);
            if (perms.ToString().Contains(SPBasePermissions.Open.ToString())
                    || perms.ToString().Contains(SPBasePermissions.FullMask.ToString()))
                hasPermission = true;
            if (!hasPermission)
            {
                // Check the users groups - this is for indirect membership;
                foreach (string groupLoginName in this.GetCurrentUserADGroups())
                {
                    try
                    {
                        SPUser groupUser = web.SiteUsers[groupLoginName];

                        perms = this.GetPermissionsForUser(ref groupUser, ref web);
                        if (perms.ToString().Contains(SPBasePermissions.Open.ToString())
                            || perms.ToString().Contains(SPBasePermissions.FullMask.ToString()))
                        {
                            hasPermission = true;
                            break;
                        }
                    }
                    catch { }
                }
            }

            return hasPermission;
        }

        private SPBasePermissions GetPermissionsForUser(ref SPUser user, ref SPWeb web)
        {
            SPBasePermissions perms = SPBasePermissions.EmptyMask;

            try
            {
                SPUserToken userToken = user.UserToken;
                System.Reflection.MethodInfo getPermissions = typeof(Microsoft.SharePoint.Utilities.SPUtility).GetMethod(&quot;GetPermissions&quot;,
                    System.Reflection.BindingFlags.NonPublic |
                    System.Reflection.BindingFlags.Public |
                    System.Reflection.BindingFlags.Instance |
                    System.Reflection.BindingFlags.InvokeMethod |
                    System.Reflection.BindingFlags.Static);

                perms = (SPBasePermissions)getPermissions.Invoke(null, new object[] { userToken, web });
            }
            catch { }

            return perms;
        }

        private System.Collections.ArrayList GetCurrentUserADGroups()
        {
			// Get the current groups for the logged in user;
            System.Collections.ArrayList groups = new System.Collections.ArrayList();
            foreach (System.Security.Principal.IdentityReference group in System.Web.HttpContext.Current.Request.LogonUserIdentity.Groups)
            {
                groups.Add(group.Translate(typeof (System.Security.Principal.NTAccount)).ToString());
            }
            return groups;
        }
</pre>
</pre>
<p>Note that in the above method is checking for <a title="SPBasePermissions Enumeration" href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx">SPBasePermissions</a> of Open and FullMask.</p>
<p>The supporting methods are also included.  After checking the permissions on the web object for the current logged in user, if not permissions have been granted we continue to check each Active Directory group that the current user is a member of.</p>
<p><map name='google_ad_map_189_0feb153b14d1a0fb'>
<area shape='rect' href='http://imageads.googleadservices.com/pagead/imgclick/189?pos=0' coords='1,2,367,28' />
<area shape='rect' href='http://services.google.com/feedback/abg' coords='384,10,453,23'/></map>
<img usemap='#google_ad_map_189_0feb153b14d1a0fb' border='0' src='http://imageads.googleadservices.com/pagead/ads?format=468x30_aff_img&amp;client=&amp;channel=&amp;output=png&amp;cuid=189&amp;url= http%3A%2F%2Fwww.mylifeinaminute.com%2F2008%2F11%2F21%2Fcustom-method-for-checking-permissions-on-a-spweb-object%2F' /></p>]]></content:encoded>
			<wfw:commentRss>http://www.mylifeinaminute.com/2008/11/21/custom-method-for-checking-permissions-on-a-spweb-object/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: www.mylifeinaminute.com @ 2012-02-05 07:50:48 by W3 Total Cache -->
