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.

946 Part IX: Maintaining a Server in Windows SharePoint Services<br />

SharePoint farm goes live to save the performance hit of creating the site during<br />

peak times.<br />

C#<br />

public static void Create()<br />

{<br />

//Connect to the portal <strong>and</strong> get the portal context.<br />

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

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

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

//initialize user profile config manager object<br />

UserProfileManager profileManager = new UserProfileManager(context);<br />

foreach (UserProfile profile in profileManager)<br />

{<br />

Console.Write("Creating a Personal Site for " + profile["PreferredName"] + "..." );<br />

try<br />

{<br />

profile.CreatePersonalSite();<br />

Console.Write("Success!\n");<br />

}<br />

catch (PersonalSiteExistsException)<br />

{<br />

Console.Write("Site already exists!\n");<br />

}<br />

catch<br />

{<br />

// Write code to Log or Display Error<br />

}<br />

}<br />

VB.NET<br />

Public Class CreateProfiles<br />

Public Shared Sub Create()<br />

'Connect to the portal <strong>and</strong> get the portal context.<br />

Dim topology As New TopologyManager<br />

Dim portal As PortalSite = topology.PortalSites(New Uri("http://testserver"))<br />

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

'initialize user profile config manager object<br />

Dim profileManager As New UserProfileManager(context)<br />

Dim profile As UserProfile<br />

For Each profile In profileManager<br />

Console.Write(("Creating a Personal Site for "<br />

+ profile("PreferredName") + "..."))<br />

Try<br />

profile.CreatePersonalSite()<br />

Console.Write("Success!" + ControlChars.Lf)<br />

Catch<br />

Console.Write("Site Already Exists!" + ControlChars.Lf)<br />

End Try<br />

Next profile<br />

End Sub

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

Saved successfully!

Ooh no, something went wrong!