<?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>idiom</title>
	<atom:link href="http://www.idiom.ca/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.idiom.ca</link>
	<description>random stuff from small places</description>
	<lastBuildDate>Tue, 20 Sep 2011 00:02:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>SharePoint &#8211; System.IO.FileNotFound Error in Console Application</title>
		<link>http://www.idiom.ca/2011/02/sharepoint-filenotfound-console/</link>
		<comments>http://www.idiom.ca/2011/02/sharepoint-filenotfound-console/#comments</comments>
		<pubDate>Mon, 28 Feb 2011 15:21:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=461</guid>
		<description><![CDATA[I was working on a console app that would use the SharePoint API to manage/validate some site settings. After writing out the &#8220;skeleton&#8221; of the application I tried to debug it with Visual Studio to make sure everything was working so far.When the application hit the first call that referenced the SharePoint API it would [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a console app that would use the SharePoint API to manage/validate some site settings. After writing out the &#8220;skeleton&#8221; of the application I tried to debug it with Visual Studio to make sure everything was working so far.When the application hit the first call that referenced the SharePoint API it would throw a <a title="System.IO.FileNotFound" href="http://msdn.microsoft.com/en-us/library/system.io.filenotfoundexception.aspx" target="_blank">System.IO.FileNotFound</a> exception.</p>
<p> I searched around as I couldn&#8217;t understand what could be causing this. My executing account had full Rights in SharePoint, the local system and access to the database. I checked to ensure the url I was using was correct and that everything worked when viewing the site using a browser. Then I realized that Visual Studio by default sets Console applications to target x86 by default!!</p>
<p><span id="more-461"></span></p>
<table align="center">
<tbody>
<tr>
<td><!--adsenseLarge--></td>
</tr>
</tbody>
</table>
<p>This is a problem as the SharePoint API is 64bit only and my console application was running in 32bit mode. I checked Task Manager to view the running processes and sure enough my app was running with <strong>*32</strong> indicating it was running in 32bit mode.This was a quick fix as I just needed to update the Platform Target build setting to be x64 instead of x86. </p>
<p>To do this navigate to Project Properties &gt; Build tab and update the Platform Target to be x64 instead of x86. Once this is done run the application again to validate that the issue is resolved. Also make sure you <strong>update all of your build configurations</strong>. When you switch from Debug to Release the release configuration will still be set to target x86.</p>
<p>Note: Setting to AnyCPU will also work as it will run in 64bit, but since the SharePoint API is 64bit only, I suggest setting to x64 to ensure it does not run on 32bit systems.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2011/02/sharepoint-filenotfound-console/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending an Email with PowerShell</title>
		<link>http://www.idiom.ca/2011/02/sending-an-email-with-powershell/</link>
		<comments>http://www.idiom.ca/2011/02/sending-an-email-with-powershell/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 03:39:00 +0000</pubDate>
		<dc:creator>idiom</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=392</guid>
		<description><![CDATA[I was working on some build automation scripts today adding email notification of the build results. Since our automation scripts use PowerShell this is what I would be using to send the email. This turned out to be really straight forward task using the SmtpClient Class. Here is a quick example using smtpclient to send [...]]]></description>
			<content:encoded><![CDATA[<p> </p>
<p>I was working on some build automation scripts today adding email notification of the build results. Since our automation scripts use PowerShell this is what I would be using to send the email. This turned out to be really straight forward task using the <a title="SmtpClient Class" href="http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx" target="_blank">SmtpClient </a>Class.</p>
<p><span id="more-392"></span></p>
<p>Here is a quick example using smtpclient to send a simple email.</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">$emailFrom <span class="sy0">=</span> <span class="st0">&quot;fromuser@domain.com&quot;</span>
$emailTo <span class="sy0">=</span> <span class="st0">&quot;touser@domain.com&quot;</span>
$subject <span class="sy0">=</span> <span class="st0">&quot;Subject&quot;</span>
$body <span class="sy0">=</span> <span class="st0">&quot;Message body&quot;</span>
$smtpServer <span class="sy0">=</span> <span class="st0">&quot;mail.domain.com&quot;</span>
$smtp <span class="sy0">=</span> new<span class="sy0">-</span><span class="kw4">object</span> Net.<span class="me1">Mail</span>.<span class="me1">SmtpClient</span><span class="br0">&#40;</span>$smtpServer<span class="br0">&#41;</span>
$smtp.<span class="me1">Send</span><span class="br0">&#40;</span>$emailFrom, $emailTo, $subject, $body<span class="br0">&#41;</span></pre></div></div>
<p>The SMTP server I was using to relay the messages also required authentication. So I had to set the <a title="SmtpClient Credentials" href="http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.credentials.aspx" target="_blank">Credentials </a>property of the SmtpClient object.<br />
<code><br />
$smtp.Credentials = new-object System.Net.NetworkCredential("senduser", "pass")<br />
</code></p>
<p>Now you may ask how to add multiple lines to the email. There are a few ways to do this, but since this is for use internally I wanted to keep it simple so I just pass carriage return/newline <strong>`r`n`r`n</strong> at the end of the lines I want to break at.</p>
<p><!--adsenselinkad--></p>
<p>Here is an example passing sender credentials and a couple of lines in the email body.</p>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">$emailFrom <span class="sy0">=</span> <span class="st0">&quot;fromuser@domain.com&quot;</span>
$emailTo <span class="sy0">=</span> <span class="st0">&quot;touser@domain.com&quot;</span>
$subject <span class="sy0">=</span> <span class="st0">&quot;Subject&quot;</span>
$body <span class="sy0">=</span> <span class="st0">&quot;Message body`r`n`r`n&quot;</span>
$body <span class="sy0">+=</span> <span class="st0">&quot;2nd Line`r`n`r`n&quot;</span>
$body <span class="sy0">+=</span> <span class="st0">&quot;3rd Line&quot;</span>
$smtpServer <span class="sy0">=</span> <span class="st0">&quot;mail.domain.com&quot;</span>
$smtp <span class="sy0">=</span> new<span class="sy0">-</span><span class="kw4">object</span> Net.<span class="me1">Mail</span>.<span class="me1">SmtpClient</span><span class="br0">&#40;</span>$smtpServer<span class="br0">&#41;</span>
$smtp.<span class="me1">Credentials</span> <span class="sy0">=</span> new<span class="sy0">-</span><span class="kw4">object</span> <span class="kw5">System.<span class="me1">Net</span></span>.<span class="me1">NetworkCredential</span><span class="br0">&#40;</span><span class="st0">&quot;senduser&quot;</span>, <span class="st0">&quot;pass&quot;</span><span class="br0">&#41;</span>
$smtp.<span class="me1">Send</span><span class="br0">&#40;</span>$emailFrom, $emailTo, $subject, $body<span class="br0">&#41;</span></pre></div></div>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2011/02/sending-an-email-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint &#8211; Fixing Could not load type TaxonomyPicker</title>
		<link>http://www.idiom.ca/2011/02/sharepoint-fixing-could-not-load-type-taxonomypicker/</link>
		<comments>http://www.idiom.ca/2011/02/sharepoint-fixing-could-not-load-type-taxonomypicker/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 02:26:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=363</guid>
		<description><![CDATA[I had been seeing this error time and again after recycling the app pool on one of my development boxes. After some digging online, it looks as though this is a bug that has snuck into the RTM release of SharePoint 2010. The TaxonomyPicker class does not exist within the SharePoint assembly, but the file [...]]]></description>
			<content:encoded><![CDATA[<p>I had been seeing this error time and again after recycling the app pool on one of my development boxes. After some digging online, it looks as though this is a <em>bug</em> that has snuck into the RTM release of SharePoint 2010. The TaxonomyPicker class does not exist within the SharePoint assembly, but the file is still in the control templates directory. So every time I recycle the app pool of my SharePoint web app, it tries  to load the control and fails with a type exception.</p>
<p><span id="more-363"></span></p>
<p><strong>Error</strong></p>
<p>Load control template file /_controltemplates/TaxonomyPicker_broken.ascx failed: Could not load type &#8216;Microsoft.SharePoint.Portal.WebControls.TaxonomyPicker&#8217; from assembly &#8216;Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&#8217;.</p>
<p></p>
<p><strong>The Fix&#8230;</strong><br />
<br />
To fix the issue with the error being logged in the Events Log do the following.</p>
<ol>
<li>Navigate to the controltemplates directory in the 14 hive (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14)</li>
<li>Rename TaxonomyPicker.ascx to TaxonomyPicker.broken (or remove it completely since it is never used).</li>
<li>Recycle the app pool for the SharePoint Web Application.</li>
</ol>
<p>
After the app pool recycles the control will no longer be loaded when the site initializes and you won&#8217;t be seeing the error within the event log any longer. </p>
<p><!--adsenselinkad--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2011/02/sharepoint-fixing-could-not-load-type-taxonomypicker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint &#8211; Displaying Custom Status Messages</title>
		<link>http://www.idiom.ca/2011/01/sp2010-displaying-custom-status-messages/</link>
		<comments>http://www.idiom.ca/2011/01/sp2010-displaying-custom-status-messages/#comments</comments>
		<pubDate>Thu, 06 Jan 2011 01:42:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=316</guid>
		<description><![CDATA[With SharePoint 2010 it&#8217;s much easier to display custom event &#038; status information to a user using the Javascript Object Model. One of the new classes is the UI Status class (SP.UI.Status) which allows developers the ability to display custom &#8220;status messages&#8221; to users. These can be anything from informational messages to critical errors. The following code [...]]]></description>
			<content:encoded><![CDATA[<p>With SharePoint 2010 it&#8217;s much easier to display custom event &#038; status information to a user using the Javascript Object Model. One of the new classes is the UI Status class (<a title="SP.UI.Status" href="http://msdn.microsoft.com/en-us/library/ff407795.aspx" target="_blank">SP.UI.Status</a>) which allows developers the ability to display custom &#8220;status messages&#8221; to users. These can be anything from informational messages to critical errors.</p>
<p><!--adsenselinkad--></p>
<p><span id="more-316"></span><br />
The following code displays a sample message for 5 seconds and then removes it. </p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;"><pre class="javascript" style="font-family:monospace;"><span class="sy0">&lt;</span>script type<span class="sy0">=</span><span class="st0">&quot;text/javascript&quot;</span><span class="sy0">&gt;</span><span class="co1">// &lt;</span>
<span class="co1">//First wait until the SP.js is loaded, otherwise the Notification won't work and a null reference exception is thrown</span>
ExecuteOrDelayUntilScriptLoaded<span class="br0">&#40;</span>Initialize<span class="sy0">,</span> <span class="st0">&quot;sp.js&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="co1">//Function to remove the status from the page</span>
<span class="kw2">function</span> RemoveStatus<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
SP.<span class="me1">UI</span>.<span class="kw3">Status</span>.<span class="me1">removeStatus</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">statusId</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="co1">//Fucntion called after sp.js is loaded.</span>
<span class="kw2">function</span> Initialize<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
<span class="kw1">this</span>.<span class="me1">statusId</span> <span class="sy0">=</span> SP.<span class="me1">UI</span>.<span class="kw3">Status</span>.<span class="me1">addStatus</span><span class="br0">&#40;</span><span class="st0">&quot;My Title&quot;</span><span class="sy0">,</span><span class="st0">&quot; My Message&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
SP.<span class="me1">UI</span>.<span class="kw3">Status</span>.<span class="me1">setStatusPriColor</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">statusId</span><span class="sy0">,</span> <span class="st0">&quot;Blue&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
setTimeout<span class="br0">&#40;</span>RemoveStatus<span class="sy0">,</span> 5000<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span>
<span class="sy0">&lt;/</span>script<span class="sy0">&gt;</span></pre></div></div>
<p>Messages can be displayed using the following priorities by passing the corresponding color to the SP.UI.Status.setStatusPriColor method.</p>
<table width="60%">
<tr>
<td><b>Priority</b></td>
<td><b>Color</b></td>
</tr>
<tr>
<td>Very Important</td>
<td>Red</td>
</tr>
<tr>
<td>Important</td>
<td>Yellow</td>
</tr>
<tr>
<td>Success</td>
<td>Green</td>
</tr>
<tr>
<td>Information</td>
<td>Blue</td>
</tr>
</table>
<p>One thing to note when displaying multiple messages is that the highest priority will be used. For example if you display a Very Important (Red) message and then swap out to show an informational (Blue) message. The status priority color won&#8217;t update and the second message will display as Very Important (Red).</p>
<p><!--adsenseLarge--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2011/01/sp2010-displaying-custom-status-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint &#8211; Elevating Privileges</title>
		<link>http://www.idiom.ca/2010/11/sharepoint-elevating-privileges/</link>
		<comments>http://www.idiom.ca/2010/11/sharepoint-elevating-privileges/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 04:07:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=270</guid>
		<description><![CDATA[Many times during SharePoint development you may need to execute code or access information that the current impersonated user does not have access to. An internal example of this is SharePoint elevating calls to the database. Every application user doesn&#8217;t need assigned roles in SQL Server, only the SharePoint runtime accounts need to be configured [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsenselinkad--></p>
<p>Many times during SharePoint development you may need to execute code or access information that the current impersonated user does not have access to. An internal example of this is SharePoint elevating calls to the database. Every application user doesn&#8217;t need assigned roles in SQL Server, only the SharePoint runtime accounts need to be configured for SQL Server access.</p>
<p><span id="more-270"></span><br />
The <a title="SPSecurity" href="http://msdn.microsoft.com/en-us/library/ms441329.aspx" target="_blank">SPSecurity </a>class provides the static method <a title="SPSecurity.RunWithElevatedPrivileges" href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx" target="_blank">RunWithElevatedPrivileges </a>for elevating calls. Code executing using this has Full Access so care must be taken not to elevate code that relies on authentication and/or authorization rules.</p>
<p><!--adsenseLarge--></p>
<p>Here is an example showing the syntax to define an anonymous method in the call to RunWithElevatedPrivileges<br />
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;">SPSecurity.<span class="me1">RunWithElevatedPrivileges</span><span class="br0">&#40;</span><span class="kw4">delegate</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
<span class="br0">&#123;</span>
    <span class="co1">// Code that needs to be elevated</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></div></div><br />
<strong>Note</strong> &#8211; When elevating code using RunWithElevatedPrivileges you will need to a new SPSite object within the call. Any SPSite objects that were been instantiated before the call to RunWithElevatedPrivileges would not have the required elevated access as they were created as the user being impersonated.</p>
<p><!--adsenselinkad--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2010/11/sharepoint-elevating-privileges/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint &#8211; Handling Access Denied Exceptions</title>
		<link>http://www.idiom.ca/2010/11/sharepoint-handling-access-denied-exceptions/</link>
		<comments>http://www.idiom.ca/2010/11/sharepoint-handling-access-denied-exceptions/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 20:20:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=217</guid>
		<description><![CDATA[Recently while working on a project, I ran into an issue with a site that was using forms based authentication (FBA). The application would load configuration settings before the user had logged in. If the application was in a state that the target site&#8217;s configuration had not been previously loaded &#38; cached, then the request would [...]]]></description>
			<content:encoded><![CDATA[<p><!--adsenselinkad--></p>
<p>Recently while working on a project, I ran into an issue with a site that was using forms based authentication (FBA). The application would load configuration settings before the user had logged in. If the application was in a state that the target site&#8217;s configuration had not been previously loaded &amp; cached, then the request would be made as an anonymous <em>(null)</em> user. Since some of these settings were stored as SPWeb properties and the unauthenticated user does not have the required permissions the request would be denied and the user was redirected to a page stating that access was denied and they needed to login. The problem was they didn&#8217;t have a chance to login yet?!</p>
<table width="100%">
<tr align="center">
<td>
<!--adsenseLarge-->
</td>
</tr>
</table>
<p><span id="more-217"></span></p>
<p>SharePoint &#8220;<em>handles</em>&#8221; Access denied exceptions by catching the exception internally and then redirecting the user to a landing page where they can log in to the site. By default this is generally <em>&#8220;_layouts/AccessDenied.aspx&#8221;</em>.</p>
<p>Most of the time this is an acceptable way for unauthorized exceptions to be handled as you can elevate calls when required in your code. But the scenario does arise where you may need to handle the exception within your own code, not elevate the call and not have the user redirected to an access denied page. </p>
<p>Since SharePoint redirects the request to the default Access Denied landing page you cannot catch the <strong>UnAuthorizedAccessException</strong> as the redirect causes a <em>ThreadAbortException</em> to be thrown so your code will never get executed.</p>
<p>In order to handle a thrown UnAuthorizedAccessException within your code you first need to set the property <a title="SPSeccurity.CatchAccessDeniedException" href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.catchaccessdeniedexception.aspx" target="_blank">CatchAccessDeniedException</a> (part of the SPSecurity class) to false. Doing so means that the Access exceptions aren&#8217;t handled by the SharePoint platform and the request isn&#8217;t redirected.</p>
<p>The following is some example code.</p>
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="co1">//It's a good idea to store the original value to be safe.</span>
<span class="kw4">bool</span> orgcatchvalue <span class="sy0">=</span> SPSecurity.<span class="me1">CatchAccessDeniedException</span><span class="sy0">;</span>
<span class="kw1">try</span><span class="br0">&#123;</span>
SPSecurity.<span class="me1">CatchAccessDeniedException</span> <span class="sy0">=</span> false<span class="sy0">;</span>
<span class="co1">//your code that may throw an authorization exception</span>
<span class="br0">&#125;</span>
<span class="kw1">catch</span><span class="br0">&#40;</span>UnAuthorizedAccessException<span class="br0">&#41;</span>
<span class="br0">&#123;</span>
<span class="co1">//Code to handle exception</span>
<span class="br0">&#125;</span>
<span class="kw1">finally</span>
<span class="br0">&#123;</span>
<span class="co1">//set the value back to what it was</span>
SPSecurity.<span class="me1">CatchAccessDeniedException</span> <span class="sy0">=</span> orgcatchval<span class="sy0">;</span>
<span class="br0">&#125;</span></pre></div></div>
<p>With the above example setting CatchAccessDeniedException to false allows you to handle the <em>UnAuthorizedAccessException</em> within your own code without SharePoint redirecting the request.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2010/11/sharepoint-handling-access-denied-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the WebPartStorage Attribute</title>
		<link>http://www.idiom.ca/2010/11/using-the-webpartstorage-attribute/</link>
		<comments>http://www.idiom.ca/2010/11/using-the-webpartstorage-attribute/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 18:14:59 +0000</pubDate>
		<dc:creator>idiom</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=133</guid>
		<description><![CDATA[When developing custom webparts for SharePoint you may be required to persist data using properties. Depending on the specifics of the webpart you may want the value to be customizble per user or shared among all users. To do this you can decorate the property with the WebPartStorage Attribute. If a WebPartStorageAttribute attribute is not [...]]]></description>
			<content:encoded><![CDATA[<p>When developing custom webparts for SharePoint you may be required to persist data using properties. Depending on the specifics of the webpart you may want the value to be customizble per user or shared among all users. To do this you can decorate the property with the <a title="WebPartStorage Attribute" href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpartstorageattribute.aspx" target="_blank">WebPartStorage </a>Attribute. If a WebPartStorageAttribute attribute is not specified for a property, Personal is used by default.</p>
<p><span id="more-133"></span><br />
</p>
<p><code><div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Source code</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://www.idiom.ca/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><pre class="csharp" style="font-family:monospace;"><span class="br0">&#91;</span>WebPartStorage<span class="br0">&#40;</span>Storage.<span class="me1">Shared</span><span class="br0">&#41;</span><span class="br0">&#93;</span>
<span class="kw1">public</span> Boolean MyProp
<span class="br0">&#123;</span>
   get <span class="br0">&#123;</span> <span class="kw1">return</span> _myprop<span class="sy0">;</span> <span class="br0">&#125;</span>
   set <span class="br0">&#123;</span> _myprop <span class="sy0">=</span> value<span class="sy0">;</span> <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></div></div><br />
</code></p>
<p>Valid values for WebPart storage are:</p>
<ul>
<li><strong>Storage.Shared</strong>, which means that the property is stored with the same value for all users.</li>
</ul>
<p>An example of this might be a Web Part that displays stock information and has a URL to a stock site as one if its properties. In this case, you&#8217;d probably define this property storage as <strong>Shared</strong> to make sure your part works as designed.</p>
<ul>
<li><strong>Storage.Personal</strong>, which means that the property is stored per user (the default).</li>
</ul>
<p>With the above example of a stock ticker WebPart you may have an option where users can enter in the symbols they want to follow.</p>
<ul>
<li><strong>Storage.None</strong>, which means that the property is not stored in the database, and the default value assigned by the designer is applied</li>
</ul>
<p>This may be an internal property that would be set at design time, like frequency of updates.</p>
<table width="100%">
<tbody>
<tr align="center">
<td><!--adsenseLarge--></td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2010/11/using-the-webpartstorage-attribute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Repair a Broken WebPart Page in SharePoint 2010</title>
		<link>http://www.idiom.ca/2010/11/repair-a-broken-webpart-page-in-sharepoint-2010/</link>
		<comments>http://www.idiom.ca/2010/11/repair-a-broken-webpart-page-in-sharepoint-2010/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 13:24:29 +0000</pubDate>
		<dc:creator>idiom</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=117</guid>
		<description><![CDATA[I recently ran into an issue working with some custom code and the SPLimitedWebPartManager class. One of the pages I was working with got into a funky state and was throwing an exception on load. Since the exception was being thrown when the page was loading there was no way for me to put the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently ran into an issue working with some custom code and the SPLimitedWebPartManager class. One of the pages I was working with got into a funky state and was throwing an exception on load. Since the exception was being thrown when the page was loading there was no way for me to put the page in edit mode and remove the suspect webpart. </p>
<p><span id="more-117"></span><br />
<!--adsenselinkad--></p>
<p>Using the <strong>contents=1</strong> querystring parameter you can put the page in &#8220;Maintenance mode&#8221; allowing you to remove the bad webparts.</p>
<p>Example: <em>http://yourserver/Lists/badlistpage/Allitems.aspx?contents=1</em><br />
<br />
It looks like this is a short cut to the  Maintenance page and passes the referring URL in the querystring</p>
<p>http://devbox/_layouts/spcontnt.aspx?&#038;url=%2fLists%2fbadlistpage%2fAllItems.aspx</p>
<p>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2010/11/repair-a-broken-webpart-page-in-sharepoint-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint 2010 List Types</title>
		<link>http://www.idiom.ca/2010/11/sharepoint-2010-list-types/</link>
		<comments>http://www.idiom.ca/2010/11/sharepoint-2010-list-types/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 18:33:18 +0000</pubDate>
		<dc:creator>idiom</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=88</guid>
		<description><![CDATA[Reference list of the default list types as defined in the global onet.xml file. This is not exhaustive but meant as a quick reference for development. List Name Type Id Url Solution Gallery 121 _catalogs/solutions MasterPage Gallery 116 _catalogs/masterpage UserInfo 112 _catalogs/users WebPart Gallery 113 _catalogs/wp List Template Gallery 114 _catalogs/lt Themes 123 _catalogs/theme Style [...]]]></description>
			<content:encoded><![CDATA[<div>
<p><!--adsenselinkad--><br />
<br />Reference list of the default list types as defined in the  global onet.xml file. This is not exhaustive but meant as a quick reference for development.</p>
<p><span id="more-88"></span></p>
<table width="100%">
<tbody>
<tr>
<td><strong>List Name</strong></td>
<td><strong>Type Id</strong></td>
<td><strong>Url</strong></td>
</tr>
<tr>
<td>Solution Gallery</td>
<td>121</td>
<td>_catalogs/solutions</td>
</tr>
<tr>
<td>MasterPage Gallery</td>
<td>116</td>
<td>_catalogs/masterpage</td>
</tr>
<tr>
<td>UserInfo</td>
<td>112</td>
<td>_catalogs/users</td>
</tr>
<tr>
<td>WebPart Gallery</td>
<td>113</td>
<td>_catalogs/wp</td>
</tr>
<tr>
<td>List Template Gallery</td>
<td>114</td>
<td>_catalogs/lt</td>
</tr>
<tr>
<td>Themes</td>
<td>123</td>
<td>_catalogs/theme</td>
</tr>
<tr>
<td>Style Library</td>
<td>101</td>
<td>Style Library</td>
</tr>
</tbody>
</table>
<p><br/><br/></p>
<table align="center">
<tr>
<td>
<!--adsenseLarge-->
</td>
</tr>
</table>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2010/11/sharepoint-2010-list-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WASC Threat Classification v2.0 Released</title>
		<link>http://www.idiom.ca/2010/01/wasc-threat-classification-v2-0-released/</link>
		<comments>http://www.idiom.ca/2010/01/wasc-threat-classification-v2-0-released/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 20:52:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.idiom.ca/?p=79</guid>
		<description><![CDATA[The WASC Threat Classification is an effort to classify the weaknesses and attacks that can lead to the compromise of a website, its data and or its users. The primary goal is to offer a central guide for common attacks and weaknesses. You can find the document online at http://projects.webappsec.org/Threat-Classification]]></description>
			<content:encoded><![CDATA[<p><!--adsenselinkad--></p>
<p>The WASC Threat Classification is an effort to classify the weaknesses and attacks that can lead to the compromise of a website, its data and or its users. The primary goal is to offer a central guide for common attacks and weaknesses. You can find the document online at <a href="http://projects.webappsec.org/Threat-Classification">http://projects.webappsec.org/Threat-Classification</a><strong></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.idiom.ca/2010/01/wasc-threat-classification-v2-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

