Do-It-Yourself SharePoint Tools – SPSiteLister

A while back, I wrote about my philosophy on using SharePoint tools, and how I preferred to create my own tools. A total of 1 reader wrote to me at furuknapgmail.com and asked if I could provide some examples. Don’t say I do not listen to your comments and emails, so I’m going to post some sample SharePoint tools that I have made and use on a very regular basis. The first tool is the SPSiteLister I mentioned.

First, check out the article on how to add SPDisposeCheck to the Tools menu of Visual Studio. As the comments revealed, however, I was too lazy and didn’t bother Googling first, which would have revealed that there were already several articles describing this. And no, I didn’t make SPDisposeCheck. However, the technique of adding tools to Visual Studio is very important.

The other tool I mentioned in the tools philosophy article was a tool to list sites and web applications in a farm. I call this the SPSiteLister, and I keep it as an external tool as well. Since I work on many projects at a time, or at least, need access to multiple sites in my lab, I want to list all the web applications and the root webs so that I know which site I want. Here’s the output from that tool:

Figure 1

This tool is very simple to create, but is a perfect example of the ‘create a tool when you need it’ philosophy. You may not need just this tool, but I do, which is why I made it, and it has saved me tons of time.

To make this tool, you can follow these steps:

  1. Create a new Console Application in Visual Studio
  2. Add references to Microsoft.SharePoint.dll
  3. Add the following two using-statements:
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
  4. Add the following code inside your Main method:
    SPFarm farm = SPFarm.Local;
    SPWebService webService = farm.Services.GetValue(“”);
    foreach (SPWebApplication webApp in webService.WebApplications)
    {
        using (SPSite site = webApp.Sites[0])
        {
            using (SPWeb rootWeb = site.RootWeb)
            {
                Console.WriteLine(webApp.DisplayName + ” | ” + site.Url + ” | ” + rootWeb.Title);
            }
        }
    }
  5. Compile and add the resulting .exe as an external tool in Visual Studio.

When making these tools, I add the external tool directly to the build-folder of my Visual Studio project. That way, if I need to change the tool in any way, I can simply make the changes, compile, and the new tool is available immediately. When I move to other development lab environments, I bring the entire Visual Studio project for the tool to the new lab.

I think I’ll post more info on other tools I’m using in later posts, which may or may not benefit you, but at least may give you inspiration to start thinking about creating your own toolset.

In addition, you may want to check out the free SharePoint Troubleshooting issue of Understanding SharePoint Journal by Ayman El-Hattab.

.b

Found this article valuable? Want to show your appreciation? Here are some options:

a) Click on the banners anywhere on the site to visit my blog's sponsors. They are all hand-picked and are selected based on providing great products and services to the SharePoint community.

b) Donate Bitcoins! I love Bitcoins, and you can donate if you'd like by clicking the button below.

c) Spread the word! Below, you should find links to sharing this article on your favorite social media sites. I'm an attention junkie, so sharing is caring in my book!

Pin It

Published by

Bjørn Furuknap

I previously did SharePoint. These days, I try new things to see where I can find the passion. If you have great ideas, cool projects, or is in general an awesome person, get in touch and we might find out together.

One thought on “Do-It-Yourself SharePoint Tools – SPSiteLister”

Leave a Reply

Your email address will not be published.