<?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>Scared Panda &#187; Code</title>
	<atom:link href="http://scaredpanda.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://scaredpanda.com</link>
	<description>Local T-Shirts For Local Causes</description>
	<lastBuildDate>Thu, 29 Jul 2010 18:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Value does not fall within the expected range</title>
		<link>http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/</link>
		<comments>http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 02:50:43 +0000</pubDate>
		<dc:creator>Clint</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://scaredpanda.com/?p=677</guid>
		<description><![CDATA[Ugh&#8230;Chances are if you are reading this you&#8217;ve been frustrated with SharePoint at one point or another. The &#8220;Value does not fall within the expected range&#8221; error message has plagued me ever since I started working with SharePoint. Usually this error comes up when I&#8217;m in a publishing site that has been backed up from [...]]]></description>
			<content:encoded><![CDATA[<p>Ugh&#8230;Chances are if you are reading this you&#8217;ve been frustrated with SharePoint at one point or another. The &#8220;Value does not fall within the expected range&#8221; error message has plagued me ever since I started working with SharePoint. Usually this error comes up when I&#8217;m in a publishing site that has been backed up from our development environment and restored into a production environment. The actions that throw this error are when the user clicks &#8220;Page Settings&#8221; from the Page drop down from the page editing toolbar.</p>
<p>In my case the error that&#8217;s going on here is that the page layout is not referenced as a relative url and is actually referencing the old server. To fix this issue we just need to loop through each SPWeb and update the page layouts to be relative. A little over a year ago I found a blog post online that had the solution by a very smart man who wrote a command line program to solve the issue. I am unable to find his post online today, so I decided to post my version of the code that I&#8217;ve updated to be used in a web part. I&#8217;ve compiled this code into a web part and whenever I run into the &#8220;Value does not fall within the expected range&#8221; error, I drop the web part on the home page, let it run and then delete the part off the page. 99% of time it works every time <img src='http://scaredpanda.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><span id="more-677"></span><em>Use this code at your own risk and I take no responsibility for anything bad that happens.</em></p>
<p>using System;<br />
using System.Text;<br />
using System.ComponentModel;<br />
using System.Collections.Generic;<br />
using System.Security.Permissions;</p>
<p>using System.Web;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.Design.WebControls;</p>
<p>using Microsoft.SharePoint;<br />
using Microsoft.SharePoint.Utilities;<br />
using Microsoft.SharePoint.Security;<br />
using Microsoft.SharePoint.Publishing;</p>
<p>namespace ScaredPanda<br />
{<br />
public class FixLayoutUrls : System.Web.UI.WebControls.WebParts.WebPart<br />
{</p>
<p>protected override void CreateChildControls()<br />
{<br />
SPSecurity.CodeToRunElevated ElevatedCode = new SPSecurity.CodeToRunElevated(CodeToRunElevated);<br />
SPSecurity.RunWithElevatedPrivileges(ElevatedCode);</p>
<p>base.CreateChildControls();<br />
}</p>
<p>protected void CodeToRunElevated()<br />
{<br />
try<br />
{<br />
using (SPSite oSite = new SPSite(SPContext.Current.Web.Url))<br />
{<br />
Context.Response.Write(oSite.RootWeb.Url);<br />
FixPages(oSite.RootWeb);<br />
}<br />
}<br />
catch (Exception ex)<br />
{}<br />
}</p>
<p>private void FixPages(SPWeb oWeb)<br />
{<br />
try<br />
{<br />
if (!PublishingWeb.IsPublishingWeb(oWeb)) return;</p>
<p>PublishingWeb pw = PublishingWeb.GetPublishingWeb(oWeb);<br />
SPListItemCollection oList = pw.PagesList.Items;</p>
<p>string sSiteUrl = oWeb.Site.Url;<br />
oWeb.AllowUnsafeUpdates = true;<br />
this.Context.Response.Write(&#8220;Processing &#8221; + oWeb.Title + &#8220;(&#8221; + oList.Count.ToString() + &#8221; pages)&#8230;&lt;br&gt;&#8221;);</p>
<p>foreach (SPListItem oPageItem in oList)<br />
{<br />
string s = (string)oPageItem[FieldId.PageLayout];<br />
if (s != null &amp;&amp; !s.StartsWith(sSiteUrl))<br />
{<br />
this.Context.Response.Write(&#8220;Fixing &#8221; + oPageItem.Title + &#8221; (&#8221; + oPageItem.Url + &#8220;)&lt;br&gt;&#8221;);<br />
oPageItem[FieldId.PageLayout] = sSiteUrl + s.Substring(s.IndexOf(&#8220;/&#8221;, 9));<br />
oPageItem.SystemUpdate();<br />
}<br />
}</p>
<p>foreach (SPWeb oSubWeb in oWeb.Webs)<br />
{<br />
FixPages(oSubWeb);<br />
oSubWeb.Dispose();<br />
}<br />
}</p>
<p>catch (Exception ex)<br />
{<br />
this.Context.Response.Write(&#8220;Layout fix failed at site: &#8221; + oWeb.Title + &#8220;&lt;br&gt;&#8221;);<br />
this.Context.Response.Write(ex);<br />
}<br />
}<br />
}<br />
}</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a class='DiggThisButton DiggMedium' href='http://digg.com/submit?url=http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/&amp;title=Value+does+not+fall+within+the+expected+range'></a></div><div class='dd_button'><iframe src='http://api.tweetmeme.com/button.js?url=http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/&amp;source=ScaredPanda&amp;style=normal' height='61' width='50' frameborder='0' scrolling='no'></iframe></div><div class='dd_button'><a name='fb_share' type='box_count' share_url='http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/' href='http://www.facebook.com/sharer.php'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/&amp;show_faces=false&amp;layout=button_count'  width='90px' scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:25px;' allowTransparency='true'></iframe></div><div class='dd_button'><script src='http://www.stumbleupon.com/hostedbadge.php?s=5&amp;r=http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/'></script></div><div class='dd_button'><a href='http://delicious.com/save' onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent('http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/')+'&amp;title='+encodeURIComponent('Value+does+not+fall+within+the+expected+range'),'delicious', 'toolbar=no,width=550,height=550'); return false;"><div class='delicious-normal-img'><img src='http://scaredpanda.com/wp-content/plugins/digg-digg/image/delicious.png' alt='Delicious' /><div class='delicious-normal-text' id='DD_DELICIOUS_AJAX_POST_ID'>Save</div></div></a></div></div></div><div style='clear:both'></div><!-- Social Buttons Shared Counts Generated by Digg Digg plugin v4.2, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/ -->]]></content:encoded>
			<wfw:commentRss>http://scaredpanda.com/2010/04/value-does-not-fall-within-the-expected-range/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CHIRP Radio Real Time Playlist Widget</title>
		<link>http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/</link>
		<comments>http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 23:08:51 +0000</pubDate>
		<dc:creator>Clint</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Chicago]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Jams we love]]></category>
		<category><![CDATA[Chirp Radio]]></category>
		<category><![CDATA[Widget]]></category>
		<category><![CDATA[Yahoo]]></category>

		<guid isPermaLink="false">http://scaredpanda.com/?p=331</guid>
		<description><![CDATA[I started listening to the Chicago Independent Radio Project(CHIRP) last week and was immediately hooked. Most of my music comes from listening to The Current in Minnesota and KEXP in Seattle, so I was psyched when I learned that there was a similar music station going on here in Chicago. There is a good playlist on the CHIRP Radio site, however I wanted to have something that would auto refresh on my desktop instead of having to keep a browser window open all the time. So my friends, I created a Yahoo! Widget that updates every sixty seconds and displays the current song playing on CHIRP Radio. 

In order to use this widget you must have Yahoo! Widgets installed on your system. Which you can download here. Once you have Yahoo! Widgets installed just download the CHIRP Radio Realtime Playlist Yahoo! Widget - version .1 and open it using Yahoo! Widgets. Simple as that.

Now please keep in mind that this is the first version and I will be updating the look/feel/functionality as the days go on. I just wanted to get this up and out there as soon as possible. Drop me a line if you find any bugs or have any comments.]]></description>
			<content:encoded><![CDATA[<p>I started listening to the <a title="CHIRP Radio" href="http://chirpradio.org/" target="_self">Chicago Independent Radio Project(CHIRP)</a> last week and was immediately hooked. Most of my music comes from listening to <a title="The Current" href="minnesota.publicradio.org/radio/services/the_current" target="_self">The Current</a> in Minnesota and <a title="KEXP" href="http://kexp.org" target="_self">KEXP</a> in Seattle, so I was psyched when I learned that there was a similar music station going on here in Chicago. There is a good playlist on the CHIRP Radio site, however I wanted to have something that would auto refresh on my desktop instead of having to keep a browser window open all the time. So my friends, I created a Yahoo! Widget that updates every sixty seconds and displays the current song playing on CHIRP Radio.</p>
<p>In order to use this widget you must have Yahoo! Widgets installed on your system. Which you can <a href="http://widgets.yahoo.com/">download here.</a> Once you have Yahoo! Widgets installed just download the <a title="CHIRP Radio Yahoo! Widget" href="/widgets/CHIRP Radio - Now Playing.widget" target="_self">CHIRP Radio Realtime Playlist Yahoo! Widget &#8211; version .1</a> and open it using Yahoo! Widgets. Simple as that.</p>
<p>Now please keep in mind that this is the first version and I will be updating the look/feel/functionality as the days go on. I just wanted to get this up and out there as soon as possible. Drop me a line if you find any bugs or have any comments.</p>
<p><strong>UPDATE</strong>: I removed the big CHRIP icon with a smaller icon so that there is no longer a &#8220;L&#8221; shape to the widget. Being that I wanted to have some type of identifier as to what the widget was, I put the little CHIRP bird icon on the right end of the now playing box.</p>
<p><strong>Download:</strong> <a title="CHIRP Radio Yahoo! Widget" href="/widgets/CHIRP%20Radio%20-%20Now%20Playing.widget" target="_self">CHIRP Radio Realtime Playlist Yahoo! Widget &#8211; version .1.1</a></p>
<p>Here is some background about CHIRP Radio:</p>
<p>CHIRP Radio is a non-profit, volunteer-run, music-, arts-, and culture-focused radio station transmitting live from our studios in Chicago’s North Center neighborhood from 6AM-3AM seven days a week, 365 days a year.</p>
<p>CHIRP Radio hosts curate their own shows within certain guidelines, playing an eclectic mix of independent and under-heard music from an array of genres and eras. Listeners are encouraged to make requests and generally interact with CHIRP  Radio hosts via comment, IM, or phone.</p>
<p>For now, CHIRP Radio is a web-only outlet, but the <a href="http://chicagoindieradio.org/">Chicago Independent Radio Project</a> is working to change the law at the federal level to open up new licenses in urban areas, and hopes one day to be able to apply for a low-power FM broadcast license as well. To find out more about this work, visit <a href="http://chicagoindieradio.org/">chicagoindieradio.org</a>.</p>
<p>CHIRP Radio does not air commercials, and receives no funding from corporations or the federal government. It is supported by special event revenues, small grants, and listeners like you. If you like what you hear, <a href="http://chirpradio.org/donate">please consider making a donation to support this service</a>.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a class='DiggThisButton DiggMedium' href='http://digg.com/submit?url=http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/&amp;title=CHIRP+Radio+Real+Time+Playlist+Widget'></a></div><div class='dd_button'><iframe src='http://api.tweetmeme.com/button.js?url=http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/&amp;source=ScaredPanda&amp;style=normal' height='61' width='50' frameborder='0' scrolling='no'></iframe></div><div class='dd_button'><a name='fb_share' type='box_count' share_url='http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/' href='http://www.facebook.com/sharer.php'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/&amp;show_faces=false&amp;layout=button_count'  width='90px' scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:25px;' allowTransparency='true'></iframe></div><div class='dd_button'><script src='http://www.stumbleupon.com/hostedbadge.php?s=5&amp;r=http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/'></script></div><div class='dd_button'><a href='http://delicious.com/save' onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent('http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/')+'&amp;title='+encodeURIComponent('CHIRP+Radio+Real+Time+Playlist+Widget'),'delicious', 'toolbar=no,width=550,height=550'); return false;"><div class='delicious-normal-img'><img src='http://scaredpanda.com/wp-content/plugins/digg-digg/image/delicious.png' alt='Delicious' /><div class='delicious-normal-text' id='DD_DELICIOUS_AJAX_POST_ID'>Save</div></div></a></div></div></div><div style='clear:both'></div><!-- Social Buttons Shared Counts Generated by Digg Digg plugin v4.2, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/ -->]]></content:encoded>
			<wfw:commentRss>http://scaredpanda.com/2010/01/chirp-radio-real-time-playlist-widget/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SharePoint Vanity URL Rewriting</title>
		<link>http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/</link>
		<comments>http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 17:44:05 +0000</pubDate>
		<dc:creator>Clint</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://scaredpanda.com/?p=321</guid>
		<description><![CDATA[During the day I am a software engineer and from time to time I tend to come up with some cool solutions that I think other developers would be interested in. So going forward I will be posting some code that I have built and want to share with all you other nerds out there. Here goes!

Looking around the internet I've seen that many people have been trying to implement URL rewriting in a MOSS environment. Ive implemented url redirecting with MOSS using the HTTP module route for a while now and I've documented the code I used and what parameters worked the best for me here;

Take a look and let me know if this helps you and if you have any questions. Make the jump to see the code and enjoy.]]></description>
			<content:encoded><![CDATA[<p>During the day I am a software engineer and from time to time I tend to come up with some cool solutions that I think other developers would be interested in. So going forward I will be posting some code that I have built and want to share with all you other nerds out there. Here goes!</p>
<p>Looking around the internet I&#8217;ve seen that many people have been trying to implement URL rewriting in a MOSS environment. Ive implemented url redirecting with MOSS using the HTTP module route for a while now and I&#8217;ve documented the code I used and what parameters worked the best for me here;</p>
<p>Take a look and let me know if this helps you and if you have any questions.</p>
<p>After messing around for a little bit it, I came up with a good way to do it. When I was looking for examples on the web there were a lot of people saying that it couldn&#8217;t be done. But in the end it actually didn’t take much to implement it. Here’s an HttpModule that I wrote to do the work.</p>
<p>The key pieces are the this.app.BeginRequest += new EventHandler(app_BeginRequest) which steps in front of the request and allows the module to get its redirect on. And HttpContext.Current.RewritePath(redirect, false); will push the necessary headers n such forward so that the receiving .aspx page will understand how to correctly post back.<br />
<code><br />
using System;<br />
using System.Data;<br />
using System.Data.SqlClient;<br />
using System.Reflection;<br />
using System.Collections;<br />
using System.Text;<br />
using System.Web;<br />
using System.Web.Caching;<br />
using System.Web.SessionState;<br />
using System.Security.Cryptography;<br />
using System.Configuration;<br />
using System.Threading;<br />
using System.IO;<br />
using System.Security;<br />
using System.Security.Principal;</p>
<p>namespace ScaredPanda<br />
{<br />
    public sealed class RewriteHttpModule : IHttpModule<br />
    {<br />
        HttpApplication app = null;<br />
        ///<br />
        /// Initializes the httpmodule<br />
        ///<br />
        public void Init(HttpApplication httpapp)<br />
        {<br />
            this.app = httpapp;<br />
            this.app.BeginRequest += new EventHandler(app_BeginRequest);<br />
        }</p>
<p>        public void app_BeginRequest(Object s, EventArgs e)<br />
        {<br />
            try<br />
            {<br />
        //determine if the income request is a url that we wish to rewrite.<br />
        //in this case we are looking for an extension-less request<br />
                string url = HttpContext.Current.Request.RawUrl.Trim();<br />
                if (url != string.Empty<br />
                    &#038;&#038; url != "/"<br />
                    &#038;&#038; !url.EndsWith("/pages")<br />
                    &#038;&#038; !url.Contains(".aspx")<br />
                    &#038;&#038; url.IndexOf("/", 1) == -1)<br />
                {<br />
                    //this will build out the the new url that the user is redirected<br />
                    //to ie pandas.aspx?pandaID=123<br />
                    string redirect = ReturnRedirectUrl(url.Replace("/", ""));</p>
<p>            //if you do a HttpContext.Current.RewritePath without the 'false' parameter,<br />
                    //the receiving sharepoint page will not handle post backs correctly<br />
            //this is extremely useful in situations where users/admins will be doing a<br />
                   //'site actions'  event<br />
                   HttpContext.Current.RewritePath(redirect, false);<br />
                }<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                //rubbish<br />
            }<br />
        }<br />
    }<br />
}</code></p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><script src='http://widgets.digg.com/buttons.js' type='text/javascript'></script><a class='DiggThisButton DiggMedium' href='http://digg.com/submit?url=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/&amp;title=SharePoint+Vanity+URL+Rewriting'></a></div><div class='dd_button'><iframe src='http://api.tweetmeme.com/button.js?url=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/&amp;source=ScaredPanda&amp;style=normal' height='61' width='50' frameborder='0' scrolling='no'></iframe></div><div class='dd_button'><a name='fb_share' type='box_count' share_url='http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/' href='http://www.facebook.com/sharer.php'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script></div><div class='dd_button'><iframe src='http://www.facebook.com/plugins/like.php?href=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/&amp;show_faces=false&amp;layout=button_count'  width='90px' scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:25px;' allowTransparency='true'></iframe></div><div class='dd_button'><script src='http://www.stumbleupon.com/hostedbadge.php?s=5&amp;r=http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/'></script></div><div class='dd_button'><a href='http://delicious.com/save' onclick="window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent('http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/')+'&amp;title='+encodeURIComponent('SharePoint+Vanity+URL+Rewriting'),'delicious', 'toolbar=no,width=550,height=550'); return false;"><div class='delicious-normal-img'><img src='http://scaredpanda.com/wp-content/plugins/digg-digg/image/delicious.png' alt='Delicious' /><div class='delicious-normal-text' id='DD_DELICIOUS_AJAX_POST_ID'>Save</div></div></a></div></div></div><div style='clear:both'></div><!-- Social Buttons Shared Counts Generated by Digg Digg plugin v4.2, 
    Author : Yong Mook Kim
    Website : http://www.mkyong.com/blog/digg-digg-wordpress-plugin/ -->]]></content:encoded>
			<wfw:commentRss>http://scaredpanda.com/2010/01/sharepoint-vanity-url-rewriting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
