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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

'create user profile if it doesn't exist<br />

Dim userAccount As String = userInfo(0)<br />

If Not profileManager.UserExists(userAccount) Then<br />

profileManager.CreateUserProfile(userAccount)<br />

End If 'Get the userprofile so it can be changed<br />

Dim userProfile As UserProfile = profileManager.GetUserProfile(userAccount)<br />

' Set users Preferred name to their first + last name.<br />

userProfile("PreferredName") = userInfo(2) + " " + userInfo(1)<br />

userProfile("WorkEmail") = userInfo(0) + "@domain.com"<br />

userProfile.Commit()<br />

read = fs.ReadLine()<br />

End While<br />

fs.Close()<br />

End Sub<br />

The next example demonstrates how to add the corporate Web site URL to<br />

every user’s Links Web Part. This Web Part is shown on the users’ My Site. You can<br />

use this code to add any links that you deem necessary for all users. The sample<br />

code is a function that adds the passed URL <strong>and</strong> title to the “Corporate” category.<br />

With modifications, you could also use the code to add certain links to specific sets<br />

of users.<br />

C#<br />

public static void Add(string url, string title, bool IsPublic)<br />

{<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 />

profile.QuickLinks.Add(title, url, "Corporate", IsPublic);<br />

}<br />

}<br />

VB.NET<br />

Public Shared Sub Add(url As String, title As String, IsPublic As Boolean)<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 />

profile.QuickLinks.Add(title, url, "Corporate", IsPublic)<br />

Next profile<br />

End Sub<br />

The next example shows how to create My Sites for all users in the<br />

profile database in one shot. It is often useful to create sites for all users before the

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

Saved successfully!

Ooh no, something went wrong!