Some SharePoint Portal OM basic samples

Refer to (Portal OM) and (WSS OM) for setup if you are not familiar with creating a SharePoint OM application.

We'll start with a C# Windows Form application.  I am using Microsoft.SharePoint, Microsoft.SharePoint.Portal, Microsoft.SharePoint.Portal.Alerts, Microsft.SharePoint.Portal.UserProfiles, Microsoft.SharePoint.Portal.Topology in these samples.  Use the same kind of setup in your designer that I showed in the initial Portal OM post.

To keep up with how I showed SPSite.Delete and mass alert management when introducing WSS OM, here are some simple examples of similiar tasks on the Portal side of the house.
Here is a delete portal:

private void button1_Click(object sender, System.EventArgs e)
      TopologyManager myTopologyManager =
new TopologyManager();
      PortalSite myPortalSite = myTopologyManager.PortalSites[
new Uri(textBox1.Text)];
            //You can also specify a bool of true here if you wish to remove the databases
      catch (Exception ex)

Here is some alerts based code just to get you in the right direction.  If you knew a specific alert ID you could operate against it--or you could enumerate all, look for something specific and then act accordingly.  Here is an example on doing a mass removal.  I have never had to use this... I doubt I would want to because I would want to enumerate and have some more control.

      //using Microsoft.SharePoint.Portal.Alerts
      Administration myAlertsAdministration =
new Administration();

Here is a quick sample on enumerating alerts within Portal and doing a variety of non-specific tasks (which of course you wouldn't do all at once).  Here I get to show one of the many entrypoints that utilizes PortalContext.

      //using Microsoft.SharePoint.Portal.UserProfiles
      UserProfileManager myUserProfileManager =
new UserProfileManager(myPortalContext);
      UserProfile tempUserProfile = myUserProfileManager.GetUserProfile(textBox1.Text);
      foreach (UserProfile myUserProfile in myUserProfileManager)

As you can imagine, there are a number of possibilities here in what and how you can accomplish your specific task.  You could even add alerts programatically with a little finesse.

Skip to main content