Archive for the ‘Code’ Category
Value does not fall within the expected range
Ugh…Chances are if you are reading this you’ve been frustrated with SharePoint at one point or another. The “Value does not fall within the expected range” error message has plagued me ever since I started working with SharePoint. Usually this error comes up when I’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 “Page Settings” from the Page drop down from the page editing toolbar.
In my case the error that’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’ve updated to be used in a web part. I’ve compiled this code into a web part and whenever I run into the “Value does not fall within the expected range” 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
CHIRP Radio Real Time Playlist Widget
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.
UPDATE: I removed the big CHRIP icon with a smaller icon so that there is no longer a “L” 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.
Download: CHIRP Radio Realtime Playlist Yahoo! Widget – version .1.1
Here is some background about CHIRP Radio:
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.
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.
For now, CHIRP Radio is a web-only outlet, but the Chicago Independent Radio Project 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 chicagoindieradio.org.
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, please consider making a donation to support this service.
SharePoint Vanity URL Rewriting
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.
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’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.
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.
using System;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using System.Collections;
using System.Text;
using System.Web;
using System.Web.Caching;
using System.Web.SessionState;
using System.Security.Cryptography;
using System.Configuration;
using System.Threading;
using System.IO;
using System.Security;
using System.Security.Principal;
namespace ScaredPanda
{
public sealed class RewriteHttpModule : IHttpModule
{
HttpApplication app = null;
///
/// Initializes the httpmodule
///
public void Init(HttpApplication httpapp)
{
this.app = httpapp;
this.app.BeginRequest += new EventHandler(app_BeginRequest);
}
public void app_BeginRequest(Object s, EventArgs e)
{
try
{
//determine if the income request is a url that we wish to rewrite.
//in this case we are looking for an extension-less request
string url = HttpContext.Current.Request.RawUrl.Trim();
if (url != string.Empty
&& url != "/"
&& !url.EndsWith("/pages")
&& !url.Contains(".aspx")
&& url.IndexOf("/", 1) == -1)
{
//this will build out the the new url that the user is redirected
//to ie pandas.aspx?pandaID=123
string redirect = ReturnRedirectUrl(url.Replace("/", ""));
//if you do a HttpContext.Current.RewritePath without the 'false' parameter,
//the receiving sharepoint page will not handle post backs correctly
//this is extremely useful in situations where users/admins will be doing a
//'site actions' event
HttpContext.Current.RewritePath(redirect, false);
}
}
catch (Exception ex)
{
//rubbish
}
}
}
}

