16.01.2013 Views

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

Microsoft Sharepoint Products and Technologies Resource Kit eBook

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 34: The SharePoint Portal Server Object Model 943<br />

objects in the <strong>Microsoft</strong>.SharePoint.Administration namespace. For example, you<br />

can get a collection of VirtualServer objects that the farm uses <strong>and</strong> then perform<br />

Windows SharePoint Services operations on those VirtualServer objects to add a<br />

Web Part to all virtual servers in the farm.<br />

Another crucial function that the <strong>Microsoft</strong>.SharePoint.Portal.Topology<br />

namespace provides is allowing you to get a PortalContext object from a Console<br />

application or a Windows Forms application. For this, you would use the Topology-<br />

Manager object to get a specific PortalSite object for the portal site you want to connect<br />

to. The following code snippet demonstrates how to get a PortalContext object<br />

from a console or Windows Forms application:<br />

C#<br />

TopologyManager topology = new TopologyManager();<br />

PortalSite portal = topology.PortalSites[new Uri("http://test-server")];<br />

PortalContext context = PortalApplication.GetContext(portal);<br />

VB.NET<br />

TopologyManager()<br />

Private Portal As PortalSite = topology.PortalSites("http://test-server")<br />

Private context As PortalContext = PortalApplication.GetContext(portal)<br />

It is important to remember that the URI you pass as an indexer in the preceding sample<br />

must be the default portal site URL. For example, if you have a portal site available<br />

at http://test-server <strong>and</strong> the URL http://192.168.0.1 also points to that site, you<br />

can only use http://test-server in the code example. Otherwise, the code will throw<br />

an exception since the object model gets the reference of the site from the database,<br />

<strong>and</strong> only the default URL is stored.<br />

<strong>Microsoft</strong>.SharePoint.Portal.UserProfiles<br />

The <strong>Microsoft</strong>.SharePoint.Portal.UserProfiles namespace is one of the most useful<br />

namespaces for Windows Forms <strong>and</strong> Console applications. It is often used to perform<br />

administrative functions. For example, if you do not have Active Directory to<br />

import user profiles from, you could use the namespace to import user profiles from<br />

any other directory service. You could also pre-create My Sites, otherwise known as<br />

Personal Sites, for all users with this namespace so that the server does not have a<br />

load spike in production when a user clicks to create a My Site. Creating My Sites are<br />

expensive in terms of processor time because they are the same as creating a new<br />

Site collection, so it can be beneficial to expend the processor time to create these<br />

before the servers go into production.<br />

With this namespace, you can also work with a user’s profile <strong>and</strong> My Site. You<br />

can add properties to the profile, add links to all users’ My Sites, or create reports to<br />

see how many users are using their My Site. This namespace provides excellent functionality<br />

for administrative functions. Because this namespace provides administrative<br />

functions, several code samples will be provided in this section for administrators,<br />

whereas other sections might provide just a description of the namespaces.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!