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.

}<br />

Chapter 36: Building Applications for <strong>Microsoft</strong> Office SharePoint Portal Server 2003 997<br />

//2. Set credentials for authentication to the Web service<br />

userProfileWS.Credentials = getUserCredentials();<br />

//3. Clear the list box on each request<br />

listBox1.Items.Clear();<br />

try<br />

{<br />

//4. Give names to the PropertyData array indexes<br />

int userProfile_GUID = 0;<br />

int accountName = 1;<br />

//5. Retrieve the PropertyData array for account name<br />

// provided by the user in the text box<br />

UserProfileWebService.PropertyData[] userData =<br />

userProfileWS.GetUserProfileByName(textBox1.Text);<br />

//6. If successful, add account name to the treeview<br />

TreeNode node = treeView1.Nodes.Add(<br />

userData[accountName].Value);<br />

//7. Save the GUID with the node<br />

node.Tag = userData[userProfile_GUID].Value;<br />

//8. For every property in the profile<br />

foreach(UserProfileWebService.PropertyData userProperty<br />

in userData)<br />

{<br />

//9. Add the name <strong>and</strong> value to the listbox<br />

listBox1.Items.Add(userProperty.Name + ": "<br />

+ userProperty.Value);<br />

}<br />

}<br />

catch<br />

{<br />

//10. Message the user if the account name is not found<br />

listBox1.Items.Add("Account Name Not Found");<br />

}<br />

Finally, place the following code in the treeView1_AfterSelect function:<br />

private void treeView1_AfterSelect(object sender,<br />

System.Windows.Forms.TreeViewEventArgs e)<br />

{<br />

//1. Establish a proxy to the UserProfileService Web Service<br />

UserProfileWebService.UserProfileService userProfileWS =<br />

new UserProfileWebService.UserProfileService();<br />

//2. Set credentials for authentication to the Web service<br />

userProfileWS.Credentials = getUserCredentials();<br />

//3. Clear the list box on each request<br />

listBox1.Items.Clear();<br />

//4. Show the clicked accountName in the text box<br />

textBox1.Text = e.Node.Text;

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

Saved successfully!

Ooh no, something went wrong!