<?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>moopoo.net &#187; SharePoint</title>
	<atom:link href="http://moopoo.net/category/sharepoint/feed/" rel="self" type="application/rss+xml" />
	<link>http://moopoo.net</link>
	<description>Fishing, technology and anything else</description>
	<lastBuildDate>Fri, 09 Dec 2011 11:04:41 +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>Disabling a SharePoint ribbon control based on user list permissions</title>
		<link>http://moopoo.net/sharepoint/disabling-a-sharepoint-ribbon-control-based-on-user-list-permissions/</link>
		<comments>http://moopoo.net/sharepoint/disabling-a-sharepoint-ribbon-control-based-on-user-list-permissions/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 11:00:00 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Permissions]]></category>
		<category><![CDATA[Ribbon]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=147</guid>
		<description><![CDATA[I had a requirement to create a button on a SharePoint list ribbon that was only enabled for Contributors of that list. The post will explain how to set that up in javascript using the SharePoint 2010 Client Object Model. I assume that you already have knowledge of working with the Ribbon in SharePoint 2010 [...]]]></description>
			<content:encoded><![CDATA[<p>I had a requirement to create a button on a SharePoint list ribbon that was only enabled for Contributors of that list. The post will explain how to set that up in javascript using the SharePoint 2010 Client Object Model.</p>
<p>I assume that you already have knowledge of working with the Ribbon in SharePoint 2010 and in particular using javascript page components. The snippets assume you have the rest of the ribbon definition in place and an existing page component file. If you don’t, I’d recommend you head on over to Chris O’Brien’s <a href="http://www.sharepointnutsandbolts.com/2010/02/ribbon-customizations-dropdown-controls.html" target="_blank">great articles</a> on ribbon customisations.</p>
<h2>Creating the button.</h2>
<p>First up we need to declare the button we wish to disable or rather enable based on the users permission. </p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">Button</span>
  <span class="attr">Id</span><span class="kwrd">=&quot;Ribbon.MyButton.Button&quot;</span>
  <span class="attr">Alt</span><span class="kwrd">=&quot;Ribbon.MyButton.Button&quot;</span>
  <span class="attr">Command</span><span class="kwrd">=&quot;Ribbon.MyButton.Button.Configure&quot;</span>
  <span class="attr">Image16by16</span><span class="kwrd">=&quot;/_layouts/images/splogo.gif&quot;</span>
  <span class="attr">Image32by32</span><span class="kwrd">=&quot;/_layouts/images/settingsIcon.png&quot;</span>
  <span class="attr">LabelText</span><span class="kwrd">=&quot;Configure&quot;</span>
  <span class="attr">Sequence</span><span class="kwrd">=&quot;10&quot;</span>
  <span class="attr">TemplateAlias</span><span class="kwrd">=&quot;o1&quot;</span>
  <span class="attr">ToolTipTitle</span><span class="kwrd">=&quot;Configure&quot;</span>
  <span class="attr">ToolTipDescription</span><span class="kwrd">=&quot;Configure merge&quot;</span> <span class="kwrd">/&gt;</span></pre>
<p>&#160;</p>
<p>The above definition is just that of an ordinary ribbon button, nothing special is declared in there. </p>
<h2>Javascript page component.</h2>
<p>The next step is to modify our page component file.</p>
<pre class="csharpcode">canHandleCommand: <span class="kwrd">function</span> (commandId) {
      <span class="kwrd">if</span>(commandId === <span class="str">'Ribbon.MyButton.Button.Configure'</span>)
        {
            <span class="kwrd">if</span>(userIsContrib == null)
            {
                checkUserIsContrib();                 </pre>
<pre class="csharpcode"><span class="kwrd">                return</span> false;
            }
            <span class="kwrd">else</span>
            {
                <span class="kwrd">return</span> userIsContrib;
            }
        }
        <span class="kwrd">else</span> {
            <span class="kwrd">return</span> <span class="kwrd">false</span>;
        }
    },</pre>
<pre class="csharpcode">...

<span class="kwrd">var</span> userIsContrib = <span class="kwrd">null</span>;

<span class="kwrd">function</span> checkUserIsContrib() {
    <span class="kwrd">var</span> context = SP.ClientContext.get_current();
    <span class="kwrd">var</span> web = context.get_web();
    list = web.get_lists().getById(SP.ListOperation.Selection.getSelectedList());

    context.load(list,<span class="str">'EffectiveBasePermissions'</span>);

    context.executeQueryAsync(Function.createDelegate(<span class="kwrd">this</span>, gotUserIsContrib), Function.createDelegate(<span class="kwrd">this</span>, failedUserIsContrib));
}

<span class="kwrd">function</span> gotUserIsContrib() {

    <span class="rem">// update the variable based on the users permission</span>
    userIsContrib = list.get_effectiveBasePermissions().has(SP.PermissionKind.editListItems);

    <span class="rem">//Update the UI</span>
    RefreshCommandUI();

}

<span class="kwrd">function</span> failedUserIsContrib() {
    alert(<span class="str">&quot;failed failedUserIsContrib&quot;</span>);
}</pre>
<p>&#160;</p>
<p>Because we want to check the user permissions asynchronously, we need to set userIsContrib initially to null. This will disable the button for all users while the checkUserIsContrib() method goes off and checks the users permissions.</p>
<p>After checking the users permissions and settings the flag appropriately we call RefreshCommandUI() which will again cause canHandleCommand to be run again. This time it will return the value that was set in the gotUserIsContrib() method. As a value has now been set on userIsContrib, no more checks against the server will be made by any other calls to RefreshCommandUI. </p>
<p>&#160;</p>
<h2>References.</h2>
<ul>
<li>&#160;<a href="http://www.sharepointnutsandbolts.com/2010/01/customizing-ribbon-part-1-creating-tabs.html" target="_blank">Chris O’Brien: Customizing the ribbon</a></li>
<li><a href="http://www.andrewconnell.com/blog/archive/2010/10/14/asynchronously-checking-if-a-command-is-available-in-the-sharepoint.aspx" target="_blank">Andrew Connell: Asynchronously Checking if a Command is Available in the SharePoint Ribbon</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/disabling-a-sharepoint-ribbon-control-based-on-user-list-permissions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programmatically checking if a user belongs to an SharePoint Audience</title>
		<link>http://moopoo.net/sharepoint/checking-if-a-user-belongs-to-an-sharepoint-audience/</link>
		<comments>http://moopoo.net/sharepoint/checking-if-a-user-belongs-to-an-sharepoint-audience/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 09:23:10 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=144</guid>
		<description><![CDATA[The following code will check if a user belongs to a given Audience in SharePoint using &#40;SPSite elevatedSite = new SPSite&#40;Microsoft.SharePoint.SPContext.Current.Site.ID&#41;&#41; &#123; &#160; SPServiceContext serviceContext = SPServiceContext.GetContext&#40;elevatedSite&#41;; AudienceManager audManager = new AudienceManager&#40;serviceContext&#41;; Audience audience = audManager.GetAudience&#40;&#34;AudienceToCheck&#34;&#41;; &#160; SPUser user = SPControl.GetContextWeb&#40;Context&#41;.CurrentUser; &#160; if &#40;audience.IsMember&#40;user.Name&#41;&#41; &#123; // do some stuff &#125; &#125;]]></description>
			<content:encoded><![CDATA[<p>The following code will check if a user belongs to a given Audience in SharePoint</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>SPSite elevatedSite <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPSite<span style="color: #000000;">&#40;</span>Microsoft.<span style="color: #0000FF;">SharePoint</span>.<span style="color: #0000FF;">SPContext</span>.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Site</span>.<span style="color: #0000FF;">ID</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
    SPServiceContext serviceContext <span style="color: #008000;">=</span> SPServiceContext.<span style="color: #0000FF;">GetContext</span><span style="color: #000000;">&#40;</span>elevatedSite<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    AudienceManager audManager <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> AudienceManager<span style="color: #000000;">&#40;</span>serviceContext<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Audience audience <span style="color: #008000;">=</span> audManager.<span style="color: #0000FF;">GetAudience</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;AudienceToCheck&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    SPUser user <span style="color: #008000;">=</span> SPControl.<span style="color: #0000FF;">GetContextWeb</span><span style="color: #000000;">&#40;</span>Context<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">CurrentUser</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>audience.<span style="color: #0000FF;">IsMember</span><span style="color: #000000;">&#40;</span>user.<span style="color: #0000FF;">Name</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
          <span style="color: #008080; font-style: italic;">// do some stuff</span>
     <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/checking-if-a-user-belongs-to-an-sharepoint-audience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Package class library as wsp for SharePoint Deployment</title>
		<link>http://moopoo.net/sharepoint/package-class-library-as-wsp-for-sharepoint-deployment/</link>
		<comments>http://moopoo.net/sharepoint/package-class-library-as-wsp-for-sharepoint-deployment/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 12:30:57 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[visual]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=133</guid>
		<description><![CDATA[Some Visual Studio solutions I&#8217;ve come across have class library projects in them. These assemblies have to subsequently be manually copied into the GAC of each SharePoint server. This goes against the standard of using wsp files to deploy assemblies and files into a SharePoint environment. Single servers are easier to manage manually copying assemblies [...]]]></description>
			<content:encoded><![CDATA[<p>Some Visual Studio solutions I&#8217;ve come across have class library projects in them. These assemblies have to subsequently be manually copied into the GAC of each SharePoint server. This goes against the standard of using wsp files to deploy assemblies and files into a SharePoint environment. Single servers are easier to manage manually copying assemblies but it&#8217;s not a very pleasant way of doing things, move into a multi server environment and you&#8217;re in a minefield.<br />
Fortunately there is an easy way to get these assemblies, plus any others you may wish to deploy at the same time, into a wsp. It takes two files and a post build event. Read on..</p>
<p>First up, we need a manifest file. This tells the environment what we would like it to do with the assembly.<br />
Create a new xml file in the root of your project called manifest.xml and add the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;?</span>xml version<span style="color: #008000;">=</span><span style="color: #666666;">&quot;1.0&quot;</span> encoding<span style="color: #008000;">=</span><span style="color: #666666;">&quot;utf-8&quot;</span> <span style="color: #008000;">?&gt;</span>
<span style="color: #008000;">&lt;</span>Solution xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://schemas.microsoft.com/sharepoint/&quot;</span>
  SolutionId<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;new guid&gt;&quot;</span><span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;</span>Assemblies<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>Assembly Location<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;assembly&gt;.dll&quot;</span> DeploymentTarget<span style="color: #008000;">=</span><span style="color: #666666;">&quot;GlobalAssemblyCache&quot;</span><span style="color: #008000;">&gt;&lt;/</span>Assembly<span style="color: #008000;">&gt;</span>
  <span style="color: #008000;">&lt;/</span>Assemblies<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>Solution<span style="color: #008000;">&gt;</span></pre></div></div>

<p>Replace &lt;new guid&gt; with a generated GUID and &lt;assembly&gt; with the name of your dll file.<br />
The DeploymentTarget attribute above specifies that it will be deployed to the GAC, you can use WebApplication if you want it to be deployed to the bin directory of your Webb Application.</p>
<p>You can also specify that the relevant line can be added to the SafeControls section of your web.config file by adding the following inside the Assembly tag above.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>SafeControls<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>SafeControl Assembly<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;assembly&gt;, Version=1.0.0.0, Culture=neutral, PublicKeyToken=&lt;public key token&gt;&quot;</span> <span style="color: #0600FF;">Namespace</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;namespace&gt;&quot;</span> TypeName<span style="color: #008000;">=</span><span style="color: #666666;">&quot;*&quot;</span> Safe<span style="color: #008000;">=</span><span style="color: #666666;">&quot;True&quot;</span> <span style="color: #008000;">/&gt;</span>
      <span style="color: #008000;">&lt;/</span>SafeControls<span style="color: #008000;">&gt;</span></pre></div></div>

<p>Next up, create a ddf file in the root of your project. I tend to name mine wsp.ddf for consistency. This will contain the instructions on what to package into the wsp file. This file should look like the following.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">;</span>Define the output directory and CAB file name <span style="color: #000000;">&#40;</span>with a wsp extension<span style="color: #000000;">&#41;</span>
.<span style="color: #0000FF;">Set</span> DiskDirectory1<span style="color: #008000;">=</span><span style="color: #666666;">&quot;bin<span style="color: #008080; font-weight: bold;">\D</span>ebug&quot;</span>
.<span style="color: #0000FF;">Set</span> CabinetNameTemplate<span style="color: #008000;">=</span><span style="color: #666666;">&quot;MySolutionName.wsp&quot;</span>
&nbsp;
<span style="color: #008000;">;</span>Include the following files <span style="color: #0600FF;">in</span> the CAB Root
manifest.<span style="color: #0000FF;">xml</span>
bin\Debug\<span style="color: #008000;">&lt;</span>assembly<span style="color: #008000;">&gt;</span>.<span style="color: #0000FF;">dll</span></pre></div></div>

<p>Now all we have left to do is add a post build event to build the wsp for us.<br />
Go to you project properties (right click project)<br />
Under the Build Events tab under Post-build event command line, enter the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">::</span> <span style="color: #0000FF;">Change</span> directory to the root of the project
cd <span style="color: #666666;">&quot;$(ProjectDir)&quot;</span>
&nbsp;
<span style="color: #008000;">::</span> <span style="color: #0000FF;">Create</span> a WSP CAB
MakeCAB <span style="color: #008000;">/</span>f <span style="color: #666666;">&quot;WSP.DDF&quot;</span></pre></div></div>

<p>You can change when the post build event runs, to your liking; normally &#8216;On successful build&#8217;.</p>
<p>That&#8217;s it when you have a successful build the wsp file will be generated ready for you to deploy, no more manual copying or editing web.config.</p>
]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/package-class-library-as-wsp-for-sharepoint-deployment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Arrays in custom web part and SharePoint Designer</title>
		<link>http://moopoo.net/sharepoint/arrays-in-custom-web-part-and-sharepoint-designer/</link>
		<comments>http://moopoo.net/sharepoint/arrays-in-custom-web-part-and-sharepoint-designer/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 16:11:12 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[SharePoint Designer]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=129</guid>
		<description><![CDATA[I came across an issue when trying to add a custom web part to a page layout in SPD. Each time I added it, the web part would error &#8220;Cannot create an object of type &#8216;Systems.Collections.ArrayList&#8217; from its string representation &#8216;Collection&#8217; for the &#8216;MyValue&#8217; property&#8221;. I narrowed it down to an ArrayList I had declared [...]]]></description>
			<content:encoded><![CDATA[<p>I came across an issue when trying to add a custom web part to a page layout in SPD.<br />
Each time I added it, the web part would error <strong>&#8220;Cannot create an object of type &#8216;Systems.Collections.ArrayList&#8217; from its string representation &#8216;Collection&#8217; for the &#8216;MyValue&#8217; property&#8221;</strong>.<br />
I narrowed it down to an ArrayList I had declared as public within the webpart. Changing this from public solved the issue for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/arrays-in-custom-web-part-and-sharepoint-designer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Required Field Validation Group on PeopleEditor control</title>
		<link>http://moopoo.net/sharepoint/required-field-validation-group-on-peopleeditor-control/</link>
		<comments>http://moopoo.net/sharepoint/required-field-validation-group-on-peopleeditor-control/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 11:34:08 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=125</guid>
		<description><![CDATA[Very similar to my post on validation of the DateTimeControl, a PeopleEditor (people picker) control I was using was validating on each postback. I created a required field validator with a ValidationGroup and to get the validator to look at the correct people editor field use the following code. myRequiredFieldValidator.ControlToValidate = string.Format&#40;&#34;{0}$downlevelTextBox&#34;, myPeopleEditor.ID&#41;;]]></description>
			<content:encoded><![CDATA[<p>Very similar to my post on <a href="http://http://moopoo.net/sharepoint/validation-group-with-sharepoint-datetimecontrol/">validation of the DateTimeControl</a>, a PeopleEditor (people picker) control I was using was validating on each postback.<br />
I created a required field validator with a ValidationGroup and to get the validator to look at the correct people editor field use the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">myRequiredFieldValidator.<span style="color: #0000FF;">ControlToValidate</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}$downlevelTextBox&quot;</span>, myPeopleEditor.<span style="color: #0000FF;">ID</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/required-field-validation-group-on-peopleeditor-control/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Removing element from web.config on feature de-activation</title>
		<link>http://moopoo.net/sharepoint/removing-element-from-web-config-on-feature-de-activation/</link>
		<comments>http://moopoo.net/sharepoint/removing-element-from-web-config-on-feature-de-activation/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 11:18:09 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=121</guid>
		<description><![CDATA[public override void FeatureDeactivating&#40;SPFeatureReceiverProperties properties&#41; &#123; &#160; SPSite site = &#40;SPSite&#41;properties.Feature.Parent; &#160; SPWebConfigModification controlsSection = new SPWebConfigModification&#40;&#34;controls&#34;, &#34;configuration/system.web/pages&#34;&#41;; controlsSection.Owner = &#34;My.Menu&#34;; controlsSection.Sequence = 20; controlsSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection; controlsSection.Value = &#34;&#60;controls&#62;&#60;/controls&#62;&#34;; &#160; SPWebConfigModification addElement = new SPWebConfigModification&#40; @&#34;add[@tagPrefix=&#34;&#34;SharePoint&#34;&#34;][@namespace=&#34;&#34;My.Menu&#34;&#34;][@assembly=&#34;&#34;My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff&#34;&#34;]&#34;, &#34;configuration/system.web/pages/controls&#34;&#41;; addElement.Owner = &#34;My.Menu&#34;; addElement.Sequence = 40; addElement.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; addElement.Value = @&#34;&#60;add tagPrefix=&#34;&#34;SharePoint&#34;&#34; namespace=&#34;&#34;My.Menu&#34;&#34; [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> FeatureDeactivating<span style="color: #000000;">&#40;</span>SPFeatureReceiverProperties properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            SPSite site <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>SPSite<span style="color: #000000;">&#41;</span>properties.<span style="color: #0000FF;">Feature</span>.<span style="color: #0000FF;">Parent</span><span style="color: #008000;">;</span>
&nbsp;
            SPWebConfigModification controlsSection <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPWebConfigModification<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;controls&quot;</span>, <span style="color: #666666;">&quot;configuration/system.web/pages&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Owner</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Sequence</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Type</span> <span style="color: #008000;">=</span> SPWebConfigModification.<span style="color: #0000FF;">SPWebConfigModificationType</span>.<span style="color: #0000FF;">EnsureSection</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&lt;controls&gt;&lt;/controls&gt;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            SPWebConfigModification addElement <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPWebConfigModification<span style="color: #000000;">&#40;</span>
                <span style="color: #666666;">@&quot;add[@tagPrefix=&quot;</span><span style="color: #666666;">&quot;SharePoint&quot;</span><span style="color: #666666;">&quot;][@namespace=&quot;</span><span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #666666;">&quot;][@assembly=&quot;</span><span style="color: #666666;">&quot;My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff&quot;</span><span style="color: #666666;">&quot;]&quot;</span>, 
                <span style="color: #666666;">&quot;configuration/system.web/pages/controls&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Owner</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Sequence</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">40</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Type</span> <span style="color: #008000;">=</span> SPWebConfigModification.<span style="color: #0000FF;">SPWebConfigModificationType</span>.<span style="color: #0000FF;">EnsureChildNode</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;&lt;add tagPrefix=&quot;</span><span style="color: #666666;">&quot;SharePoint&quot;</span><span style="color: #666666;">&quot; namespace=&quot;</span><span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #666666;">&quot; assembly=&quot;</span><span style="color: #666666;">&quot;My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff&quot;</span><span style="color: #666666;">&quot; /&gt;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">WebConfigModifications</span>.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#40;</span>controlsSection<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">WebConfigModifications</span>.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#40;</span>addElement<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">WebService</span>.<span style="color: #0000FF;">ApplyWebConfigModifications</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/removing-element-from-web-config-on-feature-de-activation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding element to web.config on feature activation</title>
		<link>http://moopoo.net/sharepoint/adding-element-to-web-config-on-feature-activation/</link>
		<comments>http://moopoo.net/sharepoint/adding-element-to-web-config-on-feature-activation/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 11:16:17 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=118</guid>
		<description><![CDATA[public override void FeatureActivated&#40;SPFeatureReceiverProperties properties&#41; &#123; &#160; SPSite site = &#40;SPSite&#41;properties.Feature.Parent; &#160; SPWebConfigModification controlsSection = new SPWebConfigModification&#40;&#34;controls&#34;, &#34;configuration/system.web/pages&#34;&#41;; controlsSection.Owner = &#34;My.Menu&#34;; controlsSection.Sequence = 20; controlsSection.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureSection; controlsSection.Value = &#34;&#60;controls&#62;&#60;/controls&#62;&#34;; &#160; SPWebConfigModification addElement = new SPWebConfigModification&#40; @&#34;add[@tagPrefix=&#34;&#34;SharePoint&#34;&#34;][@namespace=&#34;&#34;My.Menu&#34;&#34;][@assembly=&#34;&#34;My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff&#34;&#34;]&#34;, &#34;configuration/system.web/pages/controls&#34;&#41;; addElement.Owner = &#34;My.Menu&#34;; addElement.Sequence = 40; addElement.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode; addElement.Value = @&#34;&#60;add tagPrefix=&#34;&#34;SharePoint&#34;&#34; namespace=&#34;&#34;My.Menu&#34;&#34; [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> FeatureActivated<span style="color: #000000;">&#40;</span>SPFeatureReceiverProperties properties<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            SPSite site <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>SPSite<span style="color: #000000;">&#41;</span>properties.<span style="color: #0000FF;">Feature</span>.<span style="color: #0000FF;">Parent</span><span style="color: #008000;">;</span>
&nbsp;
            SPWebConfigModification controlsSection <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPWebConfigModification<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;controls&quot;</span>, <span style="color: #666666;">&quot;configuration/system.web/pages&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Owner</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Sequence</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">20</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Type</span> <span style="color: #008000;">=</span> SPWebConfigModification.<span style="color: #0000FF;">SPWebConfigModificationType</span>.<span style="color: #0000FF;">EnsureSection</span><span style="color: #008000;">;</span>
            controlsSection.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&lt;controls&gt;&lt;/controls&gt;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            SPWebConfigModification addElement <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SPWebConfigModification<span style="color: #000000;">&#40;</span>
                <span style="color: #666666;">@&quot;add[@tagPrefix=&quot;</span><span style="color: #666666;">&quot;SharePoint&quot;</span><span style="color: #666666;">&quot;][@namespace=&quot;</span><span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #666666;">&quot;][@assembly=&quot;</span><span style="color: #666666;">&quot;My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff&quot;</span><span style="color: #666666;">&quot;]&quot;</span>, 
                <span style="color: #666666;">&quot;configuration/system.web/pages/controls&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Owner</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Sequence</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">40</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Type</span> <span style="color: #008000;">=</span> SPWebConfigModification.<span style="color: #0000FF;">SPWebConfigModificationType</span>.<span style="color: #0000FF;">EnsureChildNode</span><span style="color: #008000;">;</span>
            addElement.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;&lt;add tagPrefix=&quot;</span><span style="color: #666666;">&quot;SharePoint&quot;</span><span style="color: #666666;">&quot; namespace=&quot;</span><span style="color: #666666;">&quot;My.Menu&quot;</span><span style="color: #666666;">&quot; assembly=&quot;</span><span style="color: #666666;">&quot;My.Menu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cd3368f0ff736bff&quot;</span><span style="color: #666666;">&quot; /&gt;&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">WebConfigModifications</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>controlsSection<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">WebConfigModifications</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>addElement<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            site.<span style="color: #0000FF;">WebApplication</span>.<span style="color: #0000FF;">WebService</span>.<span style="color: #0000FF;">ApplyWebConfigModifications</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/adding-element-to-web-config-on-feature-activation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Securing custom application pages in _layouts directory</title>
		<link>http://moopoo.net/sharepoint/securing-custom-application-pages-in-_layouts-directory/</link>
		<comments>http://moopoo.net/sharepoint/securing-custom-application-pages-in-_layouts-directory/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 12:04:22 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=115</guid>
		<description><![CDATA[I had a need to be able to only allow site collection admins to see some custom pages I had deployed into the _layouts directory. Create a custom code behind class for your aspx that inherits from LayoutsPageBase. Next, override the OnLoad method in your code behind and add the following code if &#40;!SPContext.Current.Web.UserIsSiteAdmin&#41; SPUtility.HandleAccessDenied&#40;new [...]]]></description>
			<content:encoded><![CDATA[<p>I had a need to be able to only allow site collection admins to see some custom pages I had deployed into the _layouts directory.<br />
Create a custom code behind class for your aspx that inherits from LayoutsPageBase.<br />
Next, override the OnLoad method in your code behind and add the following code</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>SPContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UserIsSiteAdmin</span><span style="color: #000000;">&#41;</span>
              SPUtility.<span style="color: #0000FF;">HandleAccessDenied</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> Exception<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;You need to be a site administrator to access this page.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This will redirect the user to the built in SharePoint Access denied page, for consistency.</p>
]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/securing-custom-application-pages-in-_layouts-directory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validation Group with SharePoint DateTimeControl</title>
		<link>http://moopoo.net/sharepoint/validation-group-with-sharepoint-datetimecontrol/</link>
		<comments>http://moopoo.net/sharepoint/validation-group-with-sharepoint-datetimecontrol/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 10:57:30 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=109</guid>
		<description><![CDATA[The SharePoint DateTimeControl has a property called IsRequiredField, which will act like a RequiredFieldValidator for the control. The problem is when working with web parts in SharePoint calling Page.Validate in your web part can have unexpected results. It often ends up firing validators elsewhere on the page, particularly if the web part is used on [...]]]></description>
			<content:encoded><![CDATA[<p>The SharePoint DateTimeControl has a property called IsRequiredField, which will act like a RequiredFieldValidator for the control. The problem is when working with web parts in SharePoint calling Page.Validate in your web part can have unexpected results. It often ends up firing validators elsewhere on the page, particularly if the web part is used on a list form for example.<br />
One answer of course is to use a validation group in your web part, this is where the DateTimeControl falls down as it doesn&#8217;t have this property.</p>
<p>The answer to this to create a validator in your webpart and hook it into the TextBox element of the DateTimeControl, which will then allow you to set the validation group on it.</p>
<p>To do this use the following code when you create your validator.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">valReviewDate.<span style="color: #0000FF;">ControlToValidate</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}${0}Date&quot;</span>, dteReview.<span style="color: #0000FF;">ID</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><a href="http://sharepointdata.blogspot.com/2009/06/sharepoint-datetime-control-validation.html">This post</a>, describes how to do it from code in front.</p>
]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/validation-group-with-sharepoint-datetimecontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disable Web Part button after clicking</title>
		<link>http://moopoo.net/sharepoint/disable-web-part-button/</link>
		<comments>http://moopoo.net/sharepoint/disable-web-part-button/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 10:24:40 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://moopoo.net/?p=104</guid>
		<description><![CDATA[Not sure how, I got to the end point of this so there may be other ways of doing it. Basically I had a web part the when the button was clicked I needed to disable it. Adding .Attributes["onclick"] didn&#8217;t seem to work, and after trying a few things I managed to get it working [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure how, I got to the end point of this so there may be other ways of doing it.<br />
Basically I had a web part the when the button was clicked I needed to disable it.<br />
Adding .Attributes["onclick"] didn&#8217;t seem to work, and after trying a few things I managed to get it working this way.<br />
Add the following code into OnPreRender of the web part, assuming cmdGenerate is the name of your button.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">cmdGenerate.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;onclick&quot;</span>, Page.<span style="color: #0000FF;">ClientScript</span>.<span style="color: #0000FF;">GetPostBackEventReference</span><span style="color: #000000;">&#40;</span>cmdGenerate, <span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;;this.value='Please wait...';this.disabled = true;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://moopoo.net/sharepoint/disable-web-part-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

