Tips for Devs #1: Enumerate Farm Sites and Pages
23. June 2009 08:14

I've decided to do a little series on SharePoint Tips for Developers, which will focus on common tasks that aren't immediately obvious, hopefully saving people some time in their day to day work.

Our first tip is about enumerating the objects in your farm.  Specifically, taking an SPFarm object, finding all the web applications in the farm, all the sites, and all the pages within them.  Some portion of that enumeration is likely to come up quite often in your work.

First, Getting all Web Applications in a farm is probably one of the lesser known tasks:

SPWebService webService = farm.Services.GetValue<SPWebService>("");
foreach (SPWebApplication webApp in webService.WebApplications)
{
//Do Something with Web Application here
}

In the above example, the variable farm is an SPFarm object, which you can get in a variety of ways, depending where your code is running.  In a timer job you might just do "this.Farm" -- in a web part you can get the farm from the site object in SPContext.Current.


Now we can go through all the sites and webs.  Probably the simplest way to do this is to loop through the Sites collection of your web app, and call a recursive helper function on each web, which will enumerate through all child webs regardless of depth.

        foreach (SPSite site in webApp.Sites)
{
//Pass web to helper function to enumerate
GetWeb(site.RootWeb);

}
        private void GetWeb(SPWeb web)
{
//TODO: Do something with the web object

//Process the sub webs recursively
foreach (SPWeb subweb in web.Webs)
{
GetWeb(subweb);
}
}

Once you have the web, there are a variety of ways you might find the pages you are interested in.  For example, if it is a publishing site you might want to find all the Pages libraries and get only the published pages -- You could do this with the web object you have available in GetWeb(...):

        foreach (SPList list in web.Lists)
{
if(list.Title == "Pages")
{
foreach (SPListItem item in list.Items)
{
if (item.File.Exists &&
item.File.Url.EndsWith(".aspx") &&
item.Versions[0].Level == SPFileLevel.Published)
{
//Do something clever with the page which is item.File.Url
}
}
}

Note that above we check if the item is published by looking at the level attribute of the version.

Exception: Object reference not set to an instance of an object.
Tags: , , , Comments (1) | Permalink
SharePoint at DEFCON
21. June 2009 17:38

July 31st will be a great day for SharePoint, as that's when the DEFCON 2009 conference kicks off, and this year the conference will actually have a session about SharePoint 2007!

 

So why are a bunch of hacker-types interested in an enterprise portal solution?

 

Well, the talk that will be given centers on the SharePoint 2007 Knowledge Network add-on -- For those that aren't familiar with it, it basically monitors your email interactions to learn about your skills and involvement in an organization, and then populates your SharePoint user profile with that information to enable people to leverage each other better.

 

Here is a screen shot of a Knowledge Network populates my site:

 

image

 

And of the profile manager:

 

image

 

From what I've heard, this functionality won't be included in SharePoint 2009, but undoubtedly Microsoft will continue to develop this type of technology to power the enterprise 2.0.

Exception: Object reference not set to an instance of an object.
Tags: Comments (0) | Permalink
Disable Internet Explorer Enhanced Security in Server 2008
9. May 2009 06:13

While I was setting up SharePoint in Windows Server 2008 R2 Release Candidate I was becoming quite frusterated by the Internet Explorer ESC (Enhanced Security Configuration).  It took me a while to realize you could no longer disable this through "Add/Remove Programs".  Now you need to launch the server manager, and edit this there:

image

image

 

Definitely an improvement, once you know where to look!

Exception: Object reference not set to an instance of an object.
Tags: Comments (0) | Permalink
Installing SharePoint on Windows Server 2008 R2
9. May 2009 04:54

With Windows Server 2008 R2 available as a release candidate, you may have tried installing MOSS on it already without success and received an error similar to this: "The program is blocked due to compatibility issues".

image

SharePoint SP2 enables compatibility with Server 2008 R2, so first you've got to make a slipstream install -- then you can install without any problem.

 

The steps for making a slipstreamed installation of MOSS are pretty simple. 

  • Download a MOSS image, and extract it (or copy the contents) to a folder.
  • Download WSS and MOSS SP2 patches
  • Run each patch with /extract:<c:\mymossimage>\Updates
  • Delete Wsssetup.dll from the updates folder.

Keep in mind that if you have the combined x86/64 MOSS ISO, your updates folder will be in \x64\Updates or \x86\Updates.

For the juicy details, follow the technet article:

http://technet.microsoft.com/en-us/library/cc261890.aspx

 

Once you have your slipstream image ready, you'll need to enable a few roles on your Server 2008 R2 box.

See the screen capture below for the roles I added:

image

 

Now you should be able to run the MOSS installation without any problems!

Exception: Object reference not set to an instance of an object.
Tags: Comments (0) | Permalink
Hide the First Tab on Your SharePoint Navigation
6. May 2009 15:36

By default, SharePoint will list the link to your site collection ("Home" generally) as the first 'tab' on the main navigation bar.

This is easy to remove via CSS, simply target that specific node by adding this to your style sheet:

 

#zz1_TopNavigationMenun0 {
display: none !important;
}
Exception: Object reference not set to an instance of an object.
Tags: Comments (0) | Permalink