SharePoint Internals – Hristo Pavlov’s Blog

17 July, 2008

Managing ‘Managed Paths’ through code

Filed under: SharePoint — Tags: , — hristopavlov @ 3:24 am

Today I needed to check through code whether a managed path is defined and couldn’t find any sample code or information on the net so I decided to investigate this myself.

I starting from the place where I know managed paths are shown and this is the “Defined Managed Paths” page in the Central Administration. The page is actually _admin/scprefix.aspx. I located this page in the 12 hive under 12\TEMPLATE\ADMIN and opened it up in Notepad to see which was the code behind class. It was Microsoft.SharePoint.ApplicationPages.SscPrefixPage:

<%@ Assembly Name=”Microsoft.SharePoint.ApplicationPages.Administration, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c”%>

<%@ Page Language=”C#” Inherits=”Microsoft.SharePoint.ApplicationPages.SscPrefixPage” MasterPageFile=”~/_admin/admin.master”      %>

I then located and opened the Microsoft.SharePoint.ApplicationPages.Administration assembly in Reflector and found the code behind class. After examining it for a while I found that there is a public class available that represents the collection of all managed paths inside a web application and this class is Microsoft.SharePoint.Administration.SPPrefixCollection. Then I noticed that this class has a constructor that accepts an SPWebApplication and initializes the managed paths for this web application. Unfortunately the constructor was with internal visibility. I almost started writing reflection code to call it but first decided to check the “Analyze” option in Reflector and see if any other classes are calling this constructor. Then I discovered that (logically) the SPWebApplication calls it and even has a member that represents the managed paths. This member is called Prefixes. Looking at the methods of the SPPrefixCollection class I found that checking for existing manages paths, adding new ones or deleting existing ones is supported. This is exactly what I was looking for.

// Adds the specified prefix to the collection.

public SPPrefix Add(string strPrefix, SPPrefixType type);


// Returns a Boolean value that indicates whether the collection contains the specified prefix.

public bool Contains(string strPrefix);


// Deletes the specified prefix from the collection.

public void Delete(string strPrefix);


// Deletes the specified array of prefixes from the collection.

public void Delete(string[] strPrefixes);

Now I can go and finish my code and start packing up for my 2 weeks holiday. Oh Yeah!



  1. What a coincidence that you posted this today! Was just looking for it 😉 Thanks!

    Comment by Robin — 17 July, 2008 @ 9:48 am

  2. […] Managing ‘Managed Paths’ through code […]

    Pingback by Links (7/17/2008) « Steve Pietrek - Everything SharePoint — 18 July, 2008 @ 1:41 am

  3. Would really really like to find somewhere how I list the managed paths for a Web Application – or rather, in my understanding this is the easiest way to list all the Site Collections for a given Web Application.

    Comment by dunxd — 28 November, 2008 @ 12:22 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: