Escolar Documentos
Profissional Documentos
Cultura Documentos
Table of Contents
Getting Started with SharePoint 2010 .................................................................................... 1
Getting Started ..............................................................................................................................................................2 Lab Setup Instructions ...................................................................................................................................................3 Exercise 1 Creating a Site Collection in SharePoint Central Administration ..................................................................4 Exercise 2 Working with the SharePoint 2010 Ribbon and In-place Editing .................................................................7 Exercise 3 Working with PowerShell Scripts ................................................................................................................15 Exercise 4 Programming with the SharePoint 2010 Object Model .............................................................................21
45 Minutes
demo2010
The password for the Contoso/Administrator account on all computers in this lab is: pass@word1
Additional Resources
This lab includes the following additional resources: Starter Files C:\Student\Labs\01_Roadmap\StarterFiles Files that can be used to help complete the labs. Completed lab source code in C# for Lab01_OM. Supporting presentations for the topics in this lab.
C:\Student\Labs\01_Roadmap\Solution
C:\Student\Presentations\01_Roadmap
Page 1 of 28
Getting Started
Scenario
This Hands-On Lab contains a number of additional resources in fixed locations. By default, it is assumed that the base HOL directory is C:\Student and that the labs and additional resources are located under this directory. The default working folder for this lab is C:\Student\Labs\01_Roadmap. Copying code samples from Word document Copying and pasting code from this Word document to Visual Studio is only safe for the sections of formatted code, e.g.:
Console.WriteLine("This is safe code!");
Code not in these sections may contain Unicode or other invisible characters that are not valid XML or C#/VB code, e.g.: Console.WriteLine(This is NOT safe code !!);
Page 2 of 28
Scenario
In the lab setup you will execute a PowerShell script that will create a new SharePoint site collection. Tasks Complete the following task on: demo2010 Detailed Steps
a. Start the Virtual Machine in Hyper-V. b. Log on to the Virtual Machine as the local administrator with a user name of
prompt.
e. The setup script launches a PowerShell script that creates a sample SharePoint
site at the location http://intranet.contoso.com/sites/Lab01 that you will use in the next exercises.
Page 3 of 28
Detailed Steps
a. Click Start | All Programs | Microsoft SharePoint 2010 Products | SharePoint
2010 Central Administration. Internet Explorer starts and the SharePoint Central Administration Site appears. You will now review some of the features in this site.
b. On the left-hand side of the screen, in the Quick Launch bar, click System
Administration site
Settings. The System Settings page appears. Review the system settings available on this page.
c. On the Quick Launch bar, click Monitoring.
The Monitoring page appears. Review the monitoring options available on this page.
d. On the Quick Launch bar, click Application Management.
The Application Management page appears. Review the options available on this page.
e. In the Site Collections section, click View all site collections.
Choose http://intranet.contoso.com from the Web Application drop down. review the site details in the right hand pane. Leave Internet Explorer running; you will use it in the next task.
g. In the URL list on the left hand side of the screen click /sites/broadcast and
Note: In this task you will create a new site collection and browse to the newly created site. This site will be used in later exercises.
a. On the Quick Launch bar, click Application Management.
collection
CONTOSO\Administrator
h. In the Secondary Site Collection Administrator User Name field, leave the value
Page 4 of 28
j.
Click OK. The new site provisioning process begins. When the site collection provisioning process has completed a confirmation page is provided with a hyperlink to navigate to the new site.
On the Top-Level Site Successfully Created page click the http://intranet.contoso.com/sites/Lab01A hyperlink to navigate to the new site collection. The new site collection opens in a new window. Leave the new site collection window open; you will use it in the next exercise.
Page 5 of 28
Page 6 of 28
Exercise 2 Working with the SharePoint 2010 Ribbon and In-place Editing
Scenario
In this exercise you will work with the site collection created in Exercise 1. You will: Experience the new paradigm for in-place editing by adding and viewing list items. Work with a Web Part page so you can experience how the SharePoint 2010 user interface has changed the way users manage Web Parts. Detailed Steps Note: In this task you will modify text and the default image on the home page.
a. Ensure you are viewing the Contoso Sales Site that you created in the previous
page content
exercise. Note that the home page is not default.aspx but rather a wiki page named Home.aspx. This is a wiki page located inside a library named SitePages. b. Near the top left of the page, click the Site Actions menu, and then click Edit Page. The site enters edit mode with the cursor indicating the current insert point.
Select the text Welcome to your site! and then press [Delete]. Then type Contoso Sales Site. Note the ribbon commands update to provide contextual commands editing text.
Page 7 of 28
Select the text Contoso Sales Site and use the font toolbar to change the font to 36pt and Font Color Red. Click the graphic on the right-hand side of the page and press [Delete]. On the ribbon, under Editing Tools, click the Insert tab. Click the Picture button. The Add Picture dialog box appears. Note that the Add Picture dialog box enables you to select an image which will be automatically uploaded and stored in a document library named Site Asset Library. Click Browse and navigate the following file: C:\Student\Labs\01_Roadmap\starterfiles\FrontPage.jpg then click Open. On the Select Picture dialog, click OK. On the ribbon, under Editing Tools, click the Format Text tab. On the ribbon, click Save & Close.
h. i. j. k.
In this task you will explore settings available for the site from the Site Actions menu.
a. Click the Site Actions menu, and then click Site Settings.
Settings
Page 8 of 28
b. In the Look and Feel section, click Title, description and icon.
The Title, Description and Appearance page appears. This page enables you to change the title and description you entered in the previous exercise.
c. In the Logo URL and Description section, in the URL textbox, type the following:
/_layouts/images/unknownperson.png
d. Click OK.
The Site Settings page appears. The image in the ribbon has been updated.
Page 9 of 28
Detailed Steps Note: In this task you will use the server-side ribbon and review the contextual controls that appear for items that are selected.
a. On the Quick Launch bar, in the Lists section, click Tasks.
ribbon
The task list is displayed, and is currently empty. The tasks list has an associated server-side ribbon with tabs including Browse, Share & Track, Items and List.
b. On the Ribbon, click List.
Note: In this task you will use the new dialog platform to create a task and a dependent task.
a. Click the dropdown arrow on the New Item button, and then click Task.
Page 10 of 28
Figure 9 - Tasks - New Item Dialog b. In the Title textbox, type Learn how to develop on SharePoint 2010. c. In the Priority dropdown list, select (1) High. d. In the Status dropdown list, select In Progress. e. In the % Complete textbox, type 2. f.
g. In the Description textbox, type Find out how to develop useful solutions. h. In the Start Date textbox, select date few days from today. i. j.
In the Due Date textbox, select date later than in start date. On the toolbar, click Save. The newly created task appears in the list. In the Title textbox, type Develop Solutions on SharePoint 2010. Add.
k. Click the dropdown arrow on the New Item button, and then click Task. l. m. In the Predecessors list box, select how to develop on SharePoint 2010 and click n. In the Priority dropdown list, select (1) High. o. In the Status dropdown list, select Not Started. p. In the % Complete textbox, type 0. q. In the Assigned to textbox, type Contoso\Administrator r. In the Description textbox, type Begin developing solutions on SharePoint 2010. s. In the Start Date textbox, select date which is few days from today t. Leave the Due Date textbox blank. u. On the toolbar, click Save.
Page 11 of 28
Note: In this task you will observe the in-place editing behavior as you edit a task.
a. Point to the Learn how to develop on SharePoint 2010 task, and then click the
Note that no page post backs occur; the task can be edited in-place.
c. Modify the % Complete textbox so that it reads 5 d. Click Save.
page
Note: In this task you will add a Web Part to a Web Part page using the new user interface for managing Web Parts.
a.
In Internet Explorer type following URL: http://intranet.contoso.com/sites/Lab01A/sitepages/home.aspx This URL opens a Web Part page that does not have a direct link on a newly created site. Note the ribbon options that are available for this Web Part page. Choose Edit page from Site Actions Note that the ribbon on this page has three tabs titled Browse, Page and Edit Tools. Click on each of these tabs and see how the contextual controls on the ribbon change for each of these tabs.
b. c.
Page 12 of 28
d. e.
Click on the Insert tab that takes you into the mode for adding, modifying and deleting Web Parts from the page Delete the Shared Documents Web Part in the zone by clicking on the Delete command on the Web Part menu.
Click the OK button on the Message from webpage dialog. Place your cursor below the Contoso Sales Site message On the ribbon, in the Page Tools section, click Insert. Click on the Web Part button which is shown below.
At this point you should see the new SharePoint 2010 UI for adding new Web Parts to a page. Select Lists and Libraries in the left-hand section and then select Tasks in the right-hand section. Once you have select the Tasks list, make sure the drop-down box on the far right bottom (shown below) has the Right zone selected, then click the Add button to add the Web Part instance to the page.
Page 13 of 28
k.
Save your changes by selecting the Save & Close button on the ribbon. Now that you have completed this exercise, you should have a page that looks like the one shown below.
Page 14 of 28
Detailed Steps Note: In this task you will use the PowerShell console to review the format of a PowerShell script. You will then verify the execute permissions that are configured on the Virtual Machine.
a.
Console
Launch the PowerShell console from Windows Start menu. Youll find the PowerShell shortcut in the Start menu called Windows PowerShell under Accessories. Select the Windows PowerShell shortcut, not the ISE shortcut. Please note that in this step you should be launching the PowerShell console from standard PowerShell menu item and not SharePoint-specific menu item under SharePoint folder.
At the PowerShell command prompt, type the following text: Set-Location c:\Student\Labs\01_Roadmap\Powershell\ Press [Enter]. The current folder of the PowerShell console reflects the new path. This location has several PowerShell Scripts (*.ps1 files) that will be used in this exercise.
Page 15 of 28
At the PowerShell command prompt, type the following text: Get-ChildItem Press [Enter]. PowerShell lists the scripts contained in the current location.
f. g. h. i.
At the PowerShell command prompt, type the following text: Notepad Hello.ps1 Press [Enter]. Review the contents of the hello.ps1 PowerShell file. Close Notepad. At the PowerShell command prompt, type the following text: .\Hello.ps1
j.
Press [Enter]. The script runs and a simple message is output to the PowerShell console. PowerShell Execution Policy If the PowerShell scripting support on the machine has the execution policy of restricted, the script will not run. If the execution policy has been changed to unrestricted, the console will prompt you whether to run the script or not. When writing and testing PowerShell scripts, it is easiest to change the execution policy to Bypass so that scripts can freely run without any user prompts. If your machine will not execute the .\Hello.ps1 script use the following instruction at the PowerShell command prompt: Set-ExecutionPolicyByPass
k.
Leave the PowerShell console open; you will use it in a later task.
Note: In this task you will use the Integrated Scripting Environment to edit and execute PowerShell scripts.
a.
Click Start | All Programs | Accessories | PowerShell | Windows PowerShell ISE The PowerShell Integrated Scripting Environment starts.
Page 16 of 28
Click the File menu, then click Open. Browse to the file C:\Student\Labs\01_Roadmap\Powershell\Hello.ps1 and click Open. The Hello.ps1 file appears at the top of the screen.
Click the Debug menu option and review the options, then click Run/Continue. In the Script pane at the top of the Integrated Scripting Environment edit the script so that it looks as follows: $HelloMessage = "Sample Message" Page 17 of 28
Getting Started with SharePoint 2010 Tasks Detailed Steps Write-Host "-----------------------------------" Write-Host "Hello World of Powershell Scripting" Write-Host "Host name: "$(Get-Item env:\computerName).value Write-Host $HelloMessage Write-Host "-----------------------------------"
3. Debugging a
Note: In this task you will single step through a PowerShell script.
a. In the Script pane, click in the first line of the Hello.ps1 script. b. Click the Debug menu, and click Toggle Breakpoint. c. Click the Debug menu, and click Run/Continue. d. Click OK if asked to save the script first.
The code execution pauses at the point the breakpoint was set.
Figure 18 - PowerShell Breakpoint e. Click the Debug menu, and click Step Into to step through each of the remaining
Note: In this task you will prepare the PowerShell environment to run SharePoint scripts.
a.
In the PowerShell command prompt that you left open in Task 1, type the following: Notepad LoadSharePointSnapin.ps1 Press [Enter]. Review the code and note the call to the Add-PSSnapin cmdlet. This loads the snap-in for SharePoint 2010 named Microsoft.SharePoint.PowerShell. Close Notepad. At the PowerShell command prompt, type the following text: .\LoadSharePointSnapin.ps1 Press [Enter]. At this point the PowerShell commagnds for SharePoint have been enabled. At the PowerShell command prompt, type the following text: Get-Command -PSSnapin Microsoft.SharePoint.PowerShell
b.
c. d. e. f.
Page 18 of 28
Press [Enter]. A list is returned of all the commands supported by SharePoint. At the PowerShell command prompt, type the following text: Get-Command -PSSnapin Microsoft.SharePoint.PowerShell -Verb Get Press [Enter]. A list is returned of all of the Get commands supgeported by SharePoint. At the PowerShell command prompt, type the following text: Get-Command -PSSnapin Microsoft.SharePoint.PowerShell >SP2010Cmdlets.txt Press [Enter]. This time the full list of commands are piped to a new text file. At the PowerShell command prompt, type the following text: Notepad SP2010Cmdlets.txt
m. Press [Enter].
Close Notepad.
Note: In this task you will use the PowerShell console to create a SharePoint site.
a. b.
At the PowerShell command prompt, type the following text: Get-Help New-SPSite Press [Enter]. The details for the New-SPSite command are shown. You will now create a SharePoint site using the New-SPSite object. At the PowerShell command prompt, type the following text: new-spsite -URL http://intranet.contoso.com/sites/Lab01C -OwnerAlias Contoso\Administrator -Template STS#1 -Name Lab01C Press [Enter]. When the PowerShell script completes, open Internet Explorer and review the newly created site at http://intranet.contoso.com/sites/Lab01c.
c.
d.
Page 19 of 28
Detailed Steps Note: In this task you will use and existing PowerShell script to create a SharePoint site.
a. b. c. d. e. f. g. h. i.
At the PowerShell command prompt, type the following text: Notepad CreateContosoSite.ps1 Press [Enter]. Review the details in the script file. Close Notepad. At the PowerShell command prompt, type the following text: .\CreateContosoSite.ps1 Lab01D Press [Enter]. When the PowerShell script completes a success message is returned. Type Exit and press [Enter] to leave PowerShell. Type Exit and press [Enter] to close the command Prompt. Use Internet Explorer to open the site http://intranet.contoso.com/sites/Lab01d Verify the newly created site.
Page 20 of 28
Detailed Steps Note: In this task you will configure a Visual Studio 2010 C# project to use the SharePoint object model.
a.
Console Project to use the SharePoint Object Model Complete the following task on: demo2010
Open Internet Explorer and navigate to the site http://intranet.contoso.com/sites/lab01/. This blank site was created in the Lab Setup. This is a team site. Click Start | All Programs | Microsoft Visual Studio 2010| Microsoft Visual Studio 2010. On the Start page, in the Projects section, click New Project.
b. c.
d.
Click the Target Framework dropdown at the top of the page and select .NET Framework 3.5. This step enables you to add references to the SharePoint object library. Page 21 of 28
Getting Started with SharePoint 2010 Tasks Detailed Steps SharePoint 2010 is based on .Net 3.5 and not version 4.0.
e. f. g.
In the Installed Templates section, in the Visual C# group, click Windows, then click Console Application. In the Name textbox, type Lab01_OM In the Location textbox, type c:\Student\Labs\01_Roadmap and then click OK.
In the Solution Explorer window, right-click Lab01_OM, and then click Properties. Click the Build tab. In the Platform target dropdown list, select x64 or Any CPU.
In the Solution Explorer window, right-click References, and then click Add Reference. Click the Browse tab, and then browse to the following location: C:\Program Files\Common Files\Microsoft Shared\Web Server Page 22 of 28
In the Solution Explorer window, right-click References, and then click Add Reference. Click the .NET tab. Click System.Web and then click OK.
Note: In this task you will modify the code in the Console application to enable the Developer Dashboard on a SharePoint Site. You will then alter the code and disable the dashboard.
a. b.
In the Solution Explorer window, double-click Program.cs. Paste the following code to replace the code in Program.cs : using System; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace Lab01_OM { class Program { static void Main() { SPWebService contentService = SPWebService.ContentService; SPDeveloperDashboardSettings developerDashboard =
Page 23 of 28
Getting Started with SharePoint 2010 Tasks Detailed Steps contentService.DeveloperDashboardSettings; developerDashboard.DisplayLevel = SPDeveloperDashboardLevel.On; developerDashboard.Update(); Console.WriteLine("Developer Dashboard updated."); } } } Note: if your contentService variable turns out to be null, you have to check your project properties. Good chance you havent selected the x64 platform.
c. d. e.
Press [CTRL] + [F5] to run the console application. Press a key to close the console application. Return to the Internet Explorer window that you left open in Task 1 at the following site: http://intranet.contoso.com/sites/lab01/default.aspx Press [F5] to refresh Internet Explorer. Scroll to the bottom of the page, and note that the developer dashboard is enabled.
f.
g.
In Visual Studio, update the single line of code so that the DisplayLevel value is set to Off. The code should look as follows:
using System; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace Lab01_OM { class Program { static void Main() { SPWebService contentService = SPWebService.ContentService; SPDeveloperDashboardSettings developerDashboard = contentService.DeveloperDashboardSettings; Page 24 of 28
Getting Started with SharePoint 2010 Tasks Detailed Steps developerDashboard.DisplayLevel = SPDeveloperDashboardLevel.Off; developerDashboard.Update(); Console.WriteLine("Developer Dashboard updated."); } } }
h. i. j. k.
Press [CTRL] + [F5] to run the console application. Press any key to close the console application. Return to Internet Explorer. Press [F5] to refresh Internet Explorer. Scroll to the bottom of the page, and note that the developer dashboard is now disabled.
Note: In this task you will write code that programs against the top-level site you created at the beginning of this exercise. In this task you will: Modify the Main method in program.cs to create a new SPSite object to program against the new site collection. Structure your code inside a using construct so that your code makes an implicit call to the Dispose method to prevent leakage. Obtain a reference to the SPWeb object for the top-level site and print the Title property of the site to the console window. Return to Visual Studio. In the Solution Explorer window, double-click Program.cs. Paste the following code to replace the code in Program.cs : using System; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace Lab01_OM { class Program { static void Main() { string targetSiteUrl = "http://intranet.contoso.com/sites/Lab01A"; using (SPSite siteCollection = new SPSite(targetSiteUrl)) { SPWeb site = siteCollection.RootWeb; Console.WriteLine(site.Title); Console.ReadLine(); } } } }
a. b. c.
Page 25 of 28
Press [CTRL] + [F5] to run the console application. The console application runs and displays the SharePoint site title.
When the site title is displayed, press [ENTER] to close the application.
Note: In this task you will: Add existing source files containing utility classes that program against the SharePoint 2010 object model. Modify the Main method in the console application to programmatically create a Task, Announcement and Web Part. Return to Visual Studio. In the Solution Explorer window, right-click the project Lab01_OM, and then click Add Existing Item.
a. b.
Page 26 of 28
Browse to the following location: C:\Student\Labs\01_Roadmap\StarterFiles. Click Lab01_Utilties.cs and then click Add. The Lab01_Utilties.cs source file contains three utility classes named TasksListFactory, AnnouncementsListFactory and WebPartPageDesigner. The first two classes contain code to create new list instances and to populate them with sample data. The third class named WebPartPageDesigner programs against a class named SPLimitedWebPartManager which is provided by the SharePoint 2010 object model to delete and add Web Part instance from a target Web Part Page. Paste the following code to replace the code in Program.cs : using System; using Microsoft.SharePoint; using Microsoft.SharePoint.Administration; namespace Lab01_OM {
e.
Page 27 of 28
Getting Started with SharePoint 2010 Tasks Detailed Steps class Program { static void Main() { string targetSiteUrl = "http://intranet.contoso.com/sites/Lab01A"; using (SPSite siteCollection = new SPSite(targetSiteUrl)) { SPWeb site = siteCollection.RootWeb; string TasksListTitle = "Tasks"; string TasksListDescription = "Contoso Tasks"; TasksListFactory.Create(site, TasksListTitle, TasksListDescription); string AnnouncementsListTitle = "Announcements"; string AnnouncementsListDescription = "Contoso Announcements"; AnnouncementsListFactory.Create(site, AnnouncementsListTitle, AnnouncementsListDescription); WebPartPageDesigner.ClearAll(site, "home.aspx"); WebPartPageDesigner.AddXsltListViewWebPart(site, "home.aspx", "Tasks", "Left"); WebPartPageDesigner.AddXsltListViewWebPart(site, "home.aspx", "Announcements", "Left"); } } } }
f.
Press [F5] to run the console application. The Console application adds two new lists to the target site and two new web parts to the home page to display the contents of these two lists. Return to Internet Explorer and refresh the page http://intranet.contoso.com/sites/Lab01A Review the modifications made by the console application.
g.
Page 28 of 28