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 36: Building Applications for <strong>Microsoft</strong> Office SharePoint Portal Server 2003 989<br />

7. From the Toolbox, drag a button, text box, tree view, <strong>and</strong> list box onto Form1<br />

using the default name assigned to them by Visual Studio .NET: button1,<br />

textBox1, treeView1, <strong>and</strong> listBox1, respectively.<br />

8. Double-click button1 to get to the button1_Click function in the code-behind.<br />

You will be repeatedly replacing code in this function as you explore the<br />

SharePoint Portal Server 2003 Web services.<br />

9. Double-click treeView1 to get the treeView1_AfterSelect function in the codebehind.<br />

You will also place code in this function.<br />

The following C# Windows-based application examples should run locally on<br />

your development PC using your default NTLM credentials accessing the local installation<br />

of SharePoint Portal Server 2003 from the MyComputer zone. Failing that<br />

approach, or to access a SharePoint Portal Server 2003 elsewhere, you will need to<br />

either implement Code Access Security (CAS) as described in Chapter 34, “The<br />

SharePoint Portal Server Object Model Introduction,” Chapter 35, “Building Applications<br />

Using Windows SharePoint Services Data,” <strong>and</strong> Chapter 37, “Using Visual Studio<br />

.NET to Create Web Parts,” to establish trust for the C# Windows-based application<br />

or to set up anonymous access to your portal site (only recommended for exploring<br />

what can be done with these Web services). You are now ready to begin working<br />

with the SharePoint Portal Server 2003 Web services.<br />

AreaService Web Service<br />

You created a proxy to the SharePoint Portal Server 2003 AreaService Web service<br />

named AreaWebService in the Visual Studio .NET Setup section of this chapter. Let’s<br />

begin our exploration of this Web service by retrieving the characteristics of the<br />

Home area <strong>and</strong> its subareas in a default installation of SharePoint Portal Server 2003.<br />

Clicking a node in the tree view will populate the list box with the characteristics of<br />

that area. Start by creating two private functions that perform activities that will be<br />

called from multiple places.<br />

Create a getUserCredentials function to simplify the way you authenticate to<br />

the Web services. If SharePoint Portal Server 2003 is installed locally on your PC, you<br />

can use the URL that you use to access your portal (typically http://localhost/) for the<br />

URI as shown in the code; otherwise, use the same URL referenced by your Web<br />

services.<br />

private System.Net.NetworkCredential getUserCredentials()<br />

{<br />

//1. Return a network credential from the credential cache<br />

// for the currently authenticated user.<br />

// This assumes integrated security is in use <strong>and</strong> that the<br />

// currently authenticated user has sufficient rights.<br />

return<br />

System.Net.CredentialCache.DefaultCredentials.GetCredential(<br />

new Uri("http://localhost/"), "NTLM");<br />

}

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

Saved successfully!

Ooh no, something went wrong!