How to create a SharePoint Managed Path using the object model
Posted
Tuesday, July 17, 2007 1:35 PM
by
C-Dog's .NET Tip of the Day
Ok, sometimes I post some really simple stuff. At least I think it should be simple. Today I was tasked with figuring out how to add a managed path in SharePoint using custom code. This is a fact a simple task, but knowing where to look for it is not. The first thing you need to know about the SharePoint object model is that it is all based on legacy crap that doesn't follow any naming conventions whatsoever (every object starts with SP). So knowing this, I knew I needed to create a managed path. I start by looking for stuff like SPManagedPath and SPPath, but this was to no avail. I then proceed to search google which as usual is just about useless when finding anything SharePoint related. Seems people have more questions than answers. This is why I make it a point to post everything I can on SharePoint so that other developers do not have to look so hard.
At this point, I was like well maybe I can find it using reflector. So I go and find the page that manages path in Central Administration and see that the file name is _admin/scprefix.aspx. That makes a light bulb go off in the head and I search the SDK documenation for SPPrefix and there it is. The object I needed. I got lucky today. Sometimes you have to use reflector and dig deeper. Hopefully, this lesson will help others out there on how to find things. Just about everything in WSS 3 has been called something different in WSS 2. It just takes time to learn what those changes are.
How do you add a managed path from code? Well, basically straight from the help file here. Surprisingly the help file actually had a code sample and a description of the object (this is very rare for most WSS objects).
SPContext.Current.Site.WebApplication.Prefixes.Add(somePath,
SPPrefixType.WildcardInclusion);
That's it. You can also do SPPrefixType.ExplicitInclusion, if you don't want it to recrusively manage all of the paths underneath the one you specify.
Read the complete post at http://www.dotnettipoftheday.com/blog.aspx?id=374