Developer Walkthroughs

This document is provided “as-is”. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. Some examples depicted herein are provided for illustration only and are fictitious. No real association or connection is intended or should be inferred. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. © 2010 Microsoft. All rights reserved. Microsoft, SharePoint, Visual Studio, InfoPath, and Visio are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.

Page 1

SharePoint 2010 Developer Walkthroughs

Contents
Exercise 1 – Web Part and Linq Walkthrough ....................................................................................................... 4 Task 1 - Create a new SharePoint Project ........................................................................................................ 4 Task 2 - Generate LINQ-to-SharePoint proxy class to access list data ............................................................ 7 Task 3 - Access the SharePoint list data in Visual Web Part ............................................................................ 9 Task 4 – Build and Deploy the Visual Web Part .............................................................................................. 11 Exercise 2 – Build a BCS External Content Type ................................................................................................ 16 Task 1 – Create a Business Data Catalog Model project ................................................................................ 16 Task 2 – Update the Schema of the Entity Class ............................................................................................ 18 Task 3 – Update the Service Code .................................................................................................................. 28 Task 4 – Build and Deploy ............................................................................................................................... 30 Exercise 3 – Create a Silverlight Application for the SharePoint Client Object Model ........................................ 34 Task 1 – Create a Silverlight Application Project ............................................................................................. 34 Task 2 – Write code to access and render SharePoint List Data .................................................................... 36 Task 3 – Deploy and Test using the SharePoint Silverlight web part .............................................................. 40 Exercise 4 – Creating a graph using the SharePoint Object Model and Silverlight Graphing controls ............... 42 Task 1 – Create a Silverlight Application Project ............................................................................................. 42 Task 2 – Write code to access Employee SharePoint List Data and display it in a Silverlight Graph Control 46 Task 3 – Deploy and Test using the SharePoint Silverlight Charting web part ............................................... 49 Exercise 5 – Create a Web Part for a Sandboxed Solution ................................................................................. 53 Task 1 – Create a Sandboxed Solution Project with a web part ..................................................................... 53 Task 2 – Add code to provide querying and rendering functionality ................................................................ 55 Task 3 – Build and Deploy the Sandboxed Solution ....................................................................................... 58 Exercise 6 – Creating an Activity for use in a SharePoint Designer Workflow .................................................... 63 Task 1: Create and Prepare Project ................................................................................................................ 63 Task 2: Create a new Workflow Activity for use by the Reusable Workflow ................................................... 64 Task 3: Add code to create a document library based on parameters passed to our activity. ........................ 66 Task 4: Configure activity for deployment. ....................................................................................................... 69 Task 5: Add the SPDActivityDemo activity to be deployed with SPCHOL305Ex1. ......................................... 73 Task 6: Configure a Feature using Feature Designer ..................................................................................... 74 Task 7: Add and code a Feature Receiver ...................................................................................................... 75 Task 8: Create a re-usable workflow using SharePoint Designer ................................................................... 76 Task 9: Import the reusable workflow into Visual Studio ................................................................................. 84 Task 10: Associate the workflow with a list in SharePoint ............................................................................... 91 Walkthrough Summary ......................................................................................................................................... 93

Page 2

SharePoint 2010 Developer Walkthroughs

The following six walkthroughs are C# walkthroughs of select scenarios that professional developers would do in SharePoint 2010 with Visual Studio 2010. You should find there are sufficient screenshots in these walkthroughs to read the document without having hands on access to the software. These developer walkthroughs are also available as hands on labs as part of this online eLearning course: http://MSSharePointDeveloper.com. There are additional labs in the course, there are also videos, code samples and online virtual lab environments, and the hands on labs are available in both C# and VB.NET. You are welcome to discuss these walkthroughs at http://mssharepointforums.com To provide feedback on this guide, send an e-mail message to sp2010fb@Microsoft.com.

Page 3

It will contain the rest of the development work in Exercise 1 of this lab. Enter SPCHOL200-Ex1 in the Name textbox Page 4 . Figure 1 .SharePoint 2010 Developer Walkthroughs Exercise 1 – Web Part and Linq Walkthrough Estimated time to complete this exercise: 10 minutes In this exercise. you will develop and deploy a Visual Web Part that reads data from a list and displays in a DataGrid. 2. Open Visual Studio 2010 by going to Start Menu | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010. 3. 4. Create a Visual Web Part. 4. you will: 1. In this exercise.Create a new SharePoint Project In this task. 1. Generate Linq proxy code. From the menu. select File | New | Project. Render the data using the SPDataGrid web control. 2. In the New Project dialog window. Task 1 . a solution and project will be created.SharePoint 2010 Visual Web Part Project 5. 3. choose Visual C# | SharePoint | 2010 from the Installed Templates. Use a Linq provider to read data from a SharePoint list. Select Visual Web Part from the Project Items.

SharePoint Customization Wizard 10. Click OK.com/ for the local site. Click Finish button. Set the trust level to Deploy as a farm solution. 7.SharePoint 2010 Developer Walkthroughs 6.contoso. 8. Visual Studio will create the new SPCHOL200-Ex1 project and add the necessary files. Figure 2 . 9. Uncheck Create directory for solution. Enter C:\SPHOLS\SPCHOL200\CS\Ex1 in the Location textbox. Page 5 . In the SharePoint Customization Wizard:    Enter http://intranet.

Visual Web Part 12. This will change the Title and Description property of the Visual Web Part once it is deployed. Change the value of the property element with the name attribute value of Title to SPLinqDemoTitle and the value of the property element with the name attribute value of Description to SPLinqDemoPart Description.webpart.SharePoint 2010 Developer Walkthroughs Figure 3 .SPCHOL200-Ex1 Project 11. Figure 4 . Within the Solution Explorer. Save the file. <properties> <property name="Title" type="string">SPLinqDemoTitle</property> <property name="Description" type="string">SPLinqDemoPart Description</property> </properties> Page 6 . Notice that Visual Studio also creates a Visual Web Part named VisualWebPart1. expand VisualWebPart1 and open VisualWebPart1.

1.exe /web:http://intranet. right-click on SPCHOL200-Ex1 and select Open Folder in Windows Explorer. 6. Hold Shift key and right click anywhere in the Explorer Window and select Open Command Window Here to open the command prompt window in the current project directory: Figure 5 . Type the following command in the command prompt and press Enter to set the path to the SharePoint 2010 folder: set path=%path%. spmetal.VisualWebPart1 /code:SPLinq.SharePoint 2010 Developer Walkthroughs Task 2 .cs Note – you may get warnings about content types for list Form Templates. you will use the new spmetal. 2.Generate LINQ-to-SharePoint proxy class to access list data In this task. In the Solution Explorer.exe code generation utility and generate the Linq-toSharePoint proxy code.c:\program files\common files\microsoft shared\web server extensions\14\bin 4. Page 7 .Open Command Window Here 3. Type the following command in the command prompt and press Enter to generate the Linq-toSharePoint proxy code. right click on SPCHOL200-Ex1 project and select Add | Existing Item. You can safely ignore this warning and continue 5.contoso. In Visual Studio.com /namespace:SPCHOL200_Ex1. Close the command window and switch back to Visual Studio.

SharePoint 2010 Developer Walkthroughs

Figure 6 - Add Existing Item

7. Select SPLinq.cs from the Add Existing Item dialog window and click Add:

Figure 7 - Add SPLinq.cs File

8. In the Solution Explorer, right click on References and select Add Reference. 9. Switch to Browse tab and enter C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI in the File Name text box. Press Enter to change directories. Your Add Reference window should now look like Fig. 11. 10. Select Microsoft.SharePoint.Linq.dll.

Page 8

SharePoint 2010 Developer Walkthroughs

Figure 8 - Add Reference

11. Click OK to add the reference to your project. Task 3 - Access the SharePoint list data in Visual Web Part In this task, you will add code to your solution that will allow the Visual Web Part to retrieve SharePoint list data. 1. In Solution Explorer, expand VisualWebPart1 and double-click on VisualWebPart1UserControl.ascx. 2. Visual Studio will open the Visual Web Part User Control. 3. Add the following code to the user control to construct your grid view.

Page 9

SharePoint 2010 Developer Walkthroughs

<%@ Import Namespace="Microsoft.SharePoint.WebControls" %> <SharePoint:SPGridView id="spGridView" runat="server" AutoGenerateColumns="false"> <HeaderStyle HorizontalAlign="Left" ForeColor="Navy" Font-Bold="true" /> <Columns> <SharePoint:SPBoundField DataField="Title" HeaderText="Title"></SharePoint:SPBoundField> <SharePoint:SPBoundField DataField="JobTitle" HeaderText="JobTitle"></SharePoint:SPBoundField> <SharePoint:SPBoundField DataField="ProjectTitle" HeaderText="ProjectTitle"></SharePoint:SPBoundField> <SharePoint:SPBoundField DataField="DueDate" HeaderText="DueDate"></SharePoint:SPBoundField> </Columns> </SharePoint:SPGridView>

Code Snippets: ASP.NET | spchol200_ex1_spgridview 4. The Visual Web Part user control should look like this after adding the code above:

Figure 9 - Visual Web Part User Control

5. In the Solution Explorer, right click on VisualWebPart1UserControl.ascx and select View Code. 6. Add the following using statements to the code behind:
using Microsoft.SharePoint.Linq; using Microsoft.SharePoint; using System.Linq;

Code Snippet: My Code Snippets | spchol200_ex1_namespaces 7. Insert the following code inside the Page_Load method:
var dc = new SPLinqDataContext(SPContext.Current.Web.Url); var Employees = dc.GetList<EmployeesItem>("Employees"); var empQuery = from emp in Employees

Page 10

Now. Click the Edit icon in the top menu to open the SharePoint Ribbon to the Editing Tools. Username: Administrator Password: pass@word1 4. DueDate = emp.JobTitle.DueDate < DateTime.Project.Project.com 3.DataSource = empQuery.Title.Value.contoso. ProjectTitle = emp. spGridView. In the Solution Explorer. Open Internet Explorer and browse to the following site: http://intranet.ToShortDateString() }. emp.AddMonths(6) select new { emp.Title.Project. If prompted for authentication. Page 11 . right click on SPCHOL200-Ex1 and select Deploy. enter the following details. This will build and deploy the Visual Web Part to the local SharePoint site: http://intranet. spGridView.contoso.DataBind().com Figure 10 .DueDate. Code Snippet: My Code Snippets | spchol200_ex1_pageload Task 4 – Build and Deploy the Visual Web Part 1.Deploy VisualWebPart 2.SharePoint 2010 Developer Walkthroughs where emp.

Edit Page 5.SharePoint Ribbon .SharePoint 2010 Developer Walkthroughs Figure 14 – SharePoint Edit Icon Figure 15 . Page 12 . Switch to Insert tab in the Ribbon and click on Web Part to insert a Web Part to the page.

Under Web Parts.Selecting SPlinqDemoTitle Web Part Put your cursor in the area of the page where you want the Web Part to appear. put your cursor in the zone below the Shared Page 13 . 7.SharePoint 2010 Developer Walkthroughs Figure 11 .SharePoint Ribbon . select SPLinqDemoTitle web part. This must be a zone that accepts Web Parts. In this case. Figure 12 .Insert WebPart 6. Select Custom. Under Categories.

Layout Zones 8. Page 14 .SharePoint 2010 Developer Walkthroughs Documents control. This will add the SPLinqDemoTitle web part to the selected layout zone. Figure 13 . Click Add to add the web part to the page.

Click on Page. Close Internet Explorer.SharePoint Ribbon . you built and deployed a Visual Web Part that uses Linq to SharePoint to retrieve data from a SharePoint list. In the past exercise. 11.SPLinqDemoTitle Web Part added to the layout zone 9. Close Visual Studio 2010.SharePoint 2010 Developer Walkthroughs Figure 14 . click the down arrow on the “Save and Close” button. and select Stop Editing to save the page and stop editing. Click Yes when prompted to save the changes you made. Page 15 . Figure 15 .Stop Editing 10.

Click OK. Page 16 . 5. 3. Task 1 – Create a Business Data Catalog Model project 1. Select the Visual C# | SharePoint | 2010 | Business Data Connectivity Model project template. Open Visual Studio 2010 by going to Start Menu | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010. Figure 16 .New Project Dialog 4. Enter C:\SPHOLS\SPCHOL304\CS\Ex1 in the Location textbox. and from the menu select File | New | Project.SharePoint 2010 Developer Walkthroughs Exercise 2 – Build a BCS External Content Type This exercise will guide you through creating an external content type using the Visual Studio 2010 BDC Model project template and extend the external content type. Enter BDCEx1 in the Name textbox. 2.

Figure 17 .SharePoint Customization Wizard 8. Click Finish.contoso. Select the Deploy as a farm solution radio button.com. Change the URL to http://intranet.SharePoint 2010 Developer Walkthroughs 6. Page 17 . 7.

This doesn’t help you in this case but is a good practice.SharePoint 2010 Developer Walkthroughs Task 2 – Update the Schema of the Entity Class 1.cs to Customer. rename Entity1.Visual Studio file rename prompt 2. Click Yes when prompted with the below: Figure 18 . Note when you change the Identifier1 to CustomerId. } string FirstName { get. Replace the code in the body of the Customer class with the following code. double-click on Customer. This is adding two extra properties and changing the type of a third as a mapping for the type descriptors we added and modified in the BDC definition. } string LastName { get. public public public public Int32 CustomerId { get.cs and Entity1Service. select View | Solution Explorer. From the top menu.Customer class after changes to the body Page 18 . set. In the Solution Explorer. set. set.cs. you can use the glyph that appears in the editor to rename all references to the field Identifier1. } string Message { get.cs in the Solution Explorer.cs to CustomerService. } Code Snippet: My Code Snippets | spchol304_ex1_customer Figure 19 . set. If it’s not already open.

open the BdcModel1.Solution Explorer displaying BDCModel1. Page 19 .Entity1 entity 3. Rename the Entity1 to Customer by clicking on the Entity1 name in the designer and pressing F2 (alternatively you can change the name in the Property Grid). Figure 21 .bdcm in the BDC Designer. 4. Highlight Identifier1 in the Entity designer and press F4 to open the Properties Grid. Use the Properties Grid to rename Identifier1 to CustomerId and set its Type Name to System.SharePoint 2010 Developer Walkthroughs Task 3 – Extend the BCS Metadata for the External Content Type 1. In the Solution Explorer.Int32. Figure 20 .bdcm if the BDC designer isn’t already open. In the designer select the Entity1 entity by clicking on the title. 2.

Click Entity1List to open its Property Grid. Figure 23 . rename Entity1List to CustomerList.Properties panel after the Type Name change 5. Using the Properties grid. expand Model | BDCModel1 | BDCModel1 | Customer | ReadList | returnParameter.BDC Explorer highlighting Entity1List 6. Page 20 . In the BDC Explorer in Visual Studio.SharePoint 2010 Developer Walkthroughs Figure 22 .

In the BDC Explorer. In the BDC Explorer. expand Customer and using the Properties grid rename Identifier1 to CustomerId.SharePoint 2010 Developer Walkthroughs 7.Int32. Using the Properties grid. rename Entity1 to Customer. expand CustomerList.BDC Explorer highlighting Entity1 8. Figure 24 . Figure 25 .Properties grid after changes to Identifier1 Page 21 . set the TypeName to System.

right-click returnParameter and select Paste. Figure 27 . 12. Figure 28 . Figure 26 . In the BDC Explorer right-click Customer and select Add Type Descriptor. In the BDC Explorer right-click Customer and select Copy. In the BDC Explorer expand the ReadItem method. In the BDC Explorer right-click Customer and select Add Type Descriptor. Page 22 .SharePoint 2010 Developer Walkthroughs 9.Customer entity context menu 10.Customer entity in BDC Explorer after the addition of FirstName and LastName type descriptors 13. using the Properties grid. change Name to FirstName. 11.Customer entity context menu 14. using the Properties grid. Select TypeDescriptor and. Select TypeDescriptor and. change Name to LastName.

Replace Type Descriptor prompt 16. Page 23 . Expand returnParameter | Customer and confirm FirstName and LastName type descriptors have successfully copied.SharePoint 2010 Developer Walkthroughs Figure 29 – returnParameter context menu 15. Click Yes. Figure 30 .

Step 1 to Step 18 changes Page 24 .BDC Explorer after Task 1’s.SharePoint 2010 Developer Walkthroughs Figure 31 .

Properties grid after changes to Identifier1 19.SharePoint 2010 Developer Walkthroughs 17. set the TypeName to System. 18. Using the Properties grid. rename Identifier1 to CustomerId.BDC Method Details adding Update method Page 25 .Int32. In the BDC Explorer expand the ReadItem | id and select Identifier1. Figure 32 . Using the BDC Method Details pane add an update method Figure 33 .

Adding the id parameter to the Update method Page 26 . Add a parameter and name it id Figure 34 .SharePoint 2010 Developer Walkthroughs 20.

Open the new Update method in the BDC Explorer window 22. Figure 35 . Change the Pre-Updater property on the id parameter to be True.SharePoint 2010 Developer Walkthroughs 21.Updating the Pre-Updater Field to True Page 27 . Copy the type descriptor from the CustomerId type description from @id parameter in the ReadItem method to the @id parameter in the Update method 23.

i < 10.FirstName = i + " First Name". } public static IEnumerable<Customer> ReadList() { // this is usually the first method called so check for null if (d == null) { d = new Dictionary<Int32.Message = e. } public static void Update(Customer customer.LastName = i + " Last Name".FirstName.LastName = customer. for (int i = 0. return c.FirstName = customer.Add(i.LastName. e. Int32 id) { d[id]. Replace the body of the CustomerService class with the following code. 2. c.Message.Message = i + " Item Data". e. c. e). c. and an array of customers if requested. Customer> d = null. In the Solution Explorer open the CustomerService. public static Customer ReadItem(Int32 id) { // take a copy for SharePoint Customer c = new Customer().Message.FirstName = e.cs.LastName. d. e.Message = customer.FirstName.LastName = e.CustomerId = e. Customer e = d[id]. This will return a customer based on a given id. } Code Snippet: My Code Snippets | spchol304_ex1_customerservice Page 28 . public static Dictionary<Int32. i++) { Customer e = new Customer(). Customer>(). } } return d.CustomerId. e.CustomerId = i. d[id].SharePoint 2010 Developer Walkthroughs Task 3 – Update the Service Code 1. d[id].Values. c.

feature node.SharePoint 2010 Developer Walkthroughs Figure 36 . In the Solution Explorer.contoso. This opens the feature designer.com" /> Page 29 . 6. Click the Manifest tab at the bottom of the feature designer. 4.CustomerService class after the changes 3. Add a new Property for the Site URL <Property Key="SiteUrl" Value="http://intranet. expand the Features folder and double click the Feature1. Click the + glyph next to Edit Options to open the template editor. 5.

com in a browser session. select Build | Deploy BDCEx1.contoso. 2. Click on Create. Figure 39 . From the menu. Click on Lists in the left hand navigation Figure 38 . Open http://intranet. Figure 37 – The feature designer with the SiteUrl property added Task 4 – Build and Deploy 1. 3.Lists link 4.SharePoint 2010 Developer Walkthroughs The feature designer should now look like Figure 37.Create link Page 30 .

6. Figure 32 – Create new external list page Page 31 .SharePoint 2010 Developer Walkthroughs In the Create dialog. Figure 31 – Create External List dialog 5. select External List and select Create. Click on the second button to the right of the External Content Type text box (the one with the tooltip of “Select External Content Type”). Enter My Contacts In the Name textbox.

SharePoint 2010 Developer Walkthroughs 7. Figure 33 .Customer and click OK.Business Data Type Picker -.BDCModel1.New external list page Page 32 . Select BDCEx1.Webpage Dialog Figure 40 .

Figure 41 . Click Create.External Content Type (BDC model) displayed in list Page 33 . You have just created an external content type and a list to host that content type. 9.SharePoint 2010 Developer Walkthroughs 8.

NET Framework 3. Press OK to continue.New Project Dialog 7. Select . From the menu. select File | Add | New Project. 6. Task 1 – Create a Silverlight Application Project We will start by creating a standard Silverlight application project. Name the solution Begin. 2. Page 34 . Enter C:\SPHOLS\SPCHOL306\CS\Ex1\ in the Location textbox. We will use a Visual Studio 2010 solution and deploy it to the local SharePoint server. Open Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010. In the New Project dialog box. The data for the list is retrieved from the server so it is available in Silverlight using the SharePoint Client Object Model. Figure 42 . 4. From the menu. select File | New | Project.5 5. we will create a basic Silverlight application that displays a SharePoint list inside a datagrid.SharePoint 2010 Developer Walkthroughs Exercise 3 – Create a Silverlight Application for the SharePoint Client Object Model In this exercise. 3. 1. 8. expand the Installed Templates left hand menu to Other Project Types | Visual Studio Solutions | Blank Solution.

5 11. Leave the location unchanged. Page 35 . 10. Select . 12. Figure 43 . Name the project SPSilverlightExample. Press OK to create the project.SharePoint 2010 Developer Walkthroughs 9. Press OK to continue. and choose the Silverlight Application project type in the project type list in the middle section of the screen.Add Silverlight Application Dialog 14. Figure 44 .Add New Project Dialog 13. expand the Installed Templates left hand menu to Visual C# | Silverlight.NET Framework 3. In the New Project dialog box.

16. In Visual Studio open the Toolbox and expand Silverlight Controls.ClientSilverlight.Silverlight. Select Microsoft. Browse to the “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin” folder.Add References Task 2 – Write code to access and render SharePoint List Data 1. 2. Page 36 . Right-click References in the SPSilverlightExample project and select Add References.xaml Silverlight Designer. Drag a DataGrid control onto the existing Grid in the Page.SharePoint 2010 Developer Walkthroughs 15.Runtime.dll (hold CTRL to select multiple files) 18. Press OK to add the select dll references. 17.SharePoint. Figure 45 .dll and Microsoft. Within the SPSilverlightExample project we will now add the reference assemblies to the SharePoint Silverlight Client Object Model.Client.SharePoint.

Expand the DataGrid to take up the entire page by going to the properties grid and setting its Width and Height property to Auto. its HoriztonalAlignment and VerticalAlignment properties to Stretch.DataGrid Properties Page 37 . and its Margin to 0.SharePoint 2010 Developer Walkthroughs Figure 46 . Figure 47 ..Silverlight Controls Toolbox 3.

Init(e.xaml.xaml. SynchronizationContext.Client.Threading. Also make sure to check AutoGenerateColumns (or set its value to true in the XAML). Open MainPage. Open App. Add the following code to the beginning of the Application_Startup method. Code Snippet: My Code Snippets | spchol306_ex1_app_namespaces 6.SharePoint.cs and add the following using statements to the top of the file: using Microsoft.InitParams. } public DateTime DueDate { get.AutoGenerate Columns Property 5. Add the following class before the MainPage class: public class Project { public string Title { get. Add the following code to the Page constructor below the call to InitializeComponent: Page 38 . Code Snippet: My Code Snippets | spchol306_ex1_ application_startup 7. Code Snippet: My Code Snippets | spchol306_ex1_ property 10. using System.Current). ApplicationContext.SharePoint. } public string Description { get.Client. Code Snippet: My Code Snippets | spchol306_ex1_page_namespaces 8.SharePoint 2010 Developer Walkthroughs 4. set.cs and add the following using statement to the top of the file: using Microsoft. Add the following variable to the MainPage class: private ListItemCollection _projects. Figure 48 . set. set. } } Code Snippet: My Code Snippets | spchol306_ex1_ classes 9.

context.SharePoint. The results are converted into a list of Projects and bound to the Silverlight DataGrid control.Lists. // must be on UI thread } Code Snippet: My Code Snippets | spchol306_ex1_methods This code initializes the SharePoint Silverlight client object model context (ClientContext).GetItems(query). List Projects = context. Page 39 . context.Url). query. null). context.Load(_projects).CamlQuery(). Code Snippet: My Code Snippets | spchol306_ex1_initializecomponent 11. } dataGrid1.GetByTitle("Projects").ViewXml = camlQueryXml.Client.ToString()). } private void BindData() { List<Project> projects = new List<Project>(). It then gets a reference to the Projects list and runs a simple CAML query against the list to pull all projects with a due date greater than 1/1/2008.Current. string camlQueryXml = "<View><Query><Where><Gt>" + "<FieldRef Name='Due_x0020_Date' />" + "<Value Type='DateTime'>2008-01-1T00:00:00Z</Value>" + "</Gt></Where></Query><ViewFields>" + "<FieldRef Name=\"Title\" /><FieldRef Name=\"Description\" />" + "<FieldRef Name=\"Due_x0020_Date\" />" + "</ViewFields></View>". Description = li["Description"]. Add the following code after the constructor: private void OnRequestSucceeded(Object sender. DueDate = Convert. ClientRequestSucceededEventArgs args) { // this is not called on the UI thread Dispatcher.ToDateTime(li["Due_x0020_Date"]. _projects = Projects.ItemsSource = projects.Web.Web).BeginInvoke(BindData).ToString(). context.Load(Projects). CamlQuery query = new Microsoft.SharePoint 2010 Developer Walkthroughs ClientContext context = new ClientContext(ApplicationContext.Load(context.ToString() }).Add(new Project() { Title = li["Title"]. foreach (ListItem li in _projects) { projects.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded).

Right-click the SPSilverlightExample project. 6. Figure 49 . Build the solution. 4. 8.SharePoint 2010 Developer Walkthroughs Task 3 – Deploy and Test using the SharePoint Silverlight web part To deploy the solution to SharePoint the resulting . From the Category list select Media and Content.xap as the URL. Select the Insert tab and the click Web Part. In the Silverlight Web Part dialog that pops up enter /_layouts/ClientBin/SPSilverlightExample. Change the output path to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin. 1.com. Open Internet Explorer and browse to http://intranet. and click Add.xap file has been copied to the required SharePoint directory and you are ready to add the Silverlight web part to the SharePoint website. 7. 2.contoso. choose the Silverlight Web Part from the web part list.Project Properties 3. Page 40 . The . select properties and select the Build tab.xap file created by the Silverlight project needs to be in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder. 5. Select the Edit icon at the top of the page.

SharePoint 2010 Developer Walkthroughs

Figure 50 - Silverlight Web Part Url Dialog

9. Click OK to save the Silverlight Web Part. 10. Exit edit mode. 11. The final web part will look like this on the SharePoint page:

Figure 51 - Finished Silverlight Web Part

In this exercise you have created a basic Silverlight application that displays a SharePoint list inside a datagrid. The data for the list is retrieved from the server so it is available in Silverlight using the SharePoint Client Object Model.

Page 41

SharePoint 2010 Developer Walkthroughs

Exercise 4 – Creating a graph using the SharePoint Object Model and Silverlight Graphing controls
In exercise two we will again be using the SharePoint Object Model to access SharePoint list data but this time we will use LINQ and the Silverlight Charting controls to display the data in a graph. Task 1 – Create a Silverlight Application Project 1. Open Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010. 2. From the menu, select File | New | Project. 3. In the New Project dialog box, expand the Installed Templates left hand menu to Other Project Types | Visual Studio Solutions | Blank Solution. 4. Name the solution Begin. 5. Change the location to C:\SPHOLS\SPCHOL306\CS\Ex2\

Figure 52 - New Project Dialog

6. Press OK to continue. 7. From the menu, select File | Add | New Project. Page 42

SharePoint 2010 Developer Walkthroughs

8. In the New Project dialog box, expand the Installed Templates left hand menu to Visual C# | Silverlight, and choose the Silverlight Application project type in the project type list in the middle section of the screen. 9. Name the project SilverlightEmployeeContributionsGraph. 10. Leave the location unchanged.

Figure 53 - Add New Project Dialog

Page 43

Press OK to add the select dll references. Figure 54 . Right-click References in the SilverlightEmployeeContributionsGraph project and select Add References.SharePoint.Silverlight.ClientSilverlight. 13. Browse to the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder. 14.Add Silverlight Application Dialog 12. Press OK to create the project. Click OK. Within the SPSilverlightExample project we will now add the reference assemblies to the SharePoint Silverlight Client Object Model. Select Microsoft.SharePoint 2010 Developer Walkthroughs 11.Client.dll (hold CTRL to select multiple files) 16.dll and Microsoft. 15.Runtime. Page 44 .SharePoint.

SharePoint 2010 Developer Walkthroughs Figure 55 . It is available on the . Figure 56 .Add DataVisualization Reference Page 45 .Controls.NET tab and is called the System.Windows.Toolkit. Add a reference to the Silverlight Charting Controls assembly.DataVisualization.Add References 12.

Series> <chartingToolkit:ColumnSeries ItemsSource="{Binding}" DependentValuePath="Contributions" IndependentValuePath="Name" AnimationSequence="FirstToLast" Title="Contributions" IsSelectionEnabled="True" /> </chartingToolkit:Chart. SynchronizationContext. In the Solution Explorer right-click on the App.Threading.Charting.Init(e. ApplicationContext. In the open App.Wind ows.xaml. In the XAML view of the MainPage.InitParams.Series> </chartingToolkit:Chart> Page 46 . Code Snippet: My Code Snippets | spchol306_ex2_application_startup 3.Controls. Add the following Silverlight Charting control inside the Grid element: <chartingToolkit:Chart x:Name="chart" Width="350" Height="250" Title="Team Contributions"> <chartingToolkit:Chart.Windows.SharePoint. using System.xaml file and add the following XML namespace in the UserControl element: xmlns:chartingToolkit="clrnamespace:System.cs and add the following using statements to the top of the file: using Microsoft.DataVisualization.Controls. Code Snippet: My Code Snippets | spchol306_ex2_app_namespaces 2.Current).SharePoint 2010 Developer Walkthroughs Task 2 – Write code to access Employee SharePoint List Data and display it in a Silverlight Graph Control 1.DataVisualization.Toolkit" 4.Client.xaml file and select View Code. Add the following code to the beginning of the Application_Startup method.assembly=System.

set. Code Snippet: My Code Snippets | spchol306_ex2_property 8. Add the following variable to the MainPage class: private ListItemCollection _employees.SharePoint. set.SharePoint 2010 Developer Walkthroughs Figure 57 . set. } } public class TeamContributions { public string Name { get. } public string TeamName { get. } public decimal Contributions { get. Code Snippet: My Code Snippets | spchol306_ex2_page_namespaces 6. Add the following classes before the MainPage class: public class EmployeeContributions { public string Name { get.Client.xaml. Open MainPage. set.Silverlight Chart XAML 5. set. Add the following code to the Page constructor below the call to InitializeComponent: Page 47 .cs and add the following using statement to the top of the file: using Microsoft. } public decimal Contributions { get. } } Code Snippet: My Code Snippets | spchol306_ex2_classes 7.

Url).TeamName) . Add the following code after the constructor: private void OnRequestSucceeded(Object sender.BeginInvoke(BindData).Web.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded). // must be on UI thread } Code Snippet: My Code Snippets | spchol306_ex2_methods Page 48 . chart. Code Snippet: My Code Snippets | spchol306_ex2_initializecomponent 9.GroupBy(e => e.ToString().Web). CamlQuery query = new CamlQuery().Add(new EmployeeContributions { Name = li["Title"].ViewXml = camlQueryXml.Load(context. } // use linq to group employees on team name and then total team contributions List<TeamContributions> teams = employees . TeamName = li["Team"]. ClientRequestSucceededEventArgs args) { // this is not called on the UI thread Dispatcher. context. string camlQueryXml = null.GetByTitle("Employees").ToString(). List employees = context. _employees = employees. } private void BindData() { List<EmployeeContributions> employees = new List<EmployeeContributions>().Contributions) }).ToList().Load(employees). context.Select(t => new TeamContributions { Name = t.Key. Contributions = t.SharePoint 2010 Developer Walkthroughs ClientContext context = new ClientContext(ApplicationContext. // get list item values into a strongly typed class foreach (ListItem li in _employees) { employees.GetItems(query). Contributions = Convert. context.Current. context. null).Load(_employees). query.Lists.DataContext = teams.Sum(e => e.ToDecimal(li["Contribution_x0020__x0028_in_x00"]) }).

xap file created by the Silverlight project needs to be in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin folder. Change the output path to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin. Team contributions are then set as the chart’s data source. LINQ is then used to group employees into teams and their contributions summed together. Right-click the SilverlightEmployeeContributionsGraph project. The . 2.com. Open Internet Explorer and browse to http://intranet. select properties and select the Build tab. 1.SharePoint 2010 Developer Walkthroughs 10. Once the employee contribution items have been populated into a list. Like the previous exercise the SharePoint Silverlight client object model is used to retrieve data from a SharePoint list. Page 49 . Task 3 – Deploy and Test using the SharePoint Silverlight Charting web part To deploy the solution to SharePoint the resulting . Build the solution.contoso. 4. Figure 58 .xap file has been copied to the required SharePoint directory and you are ready to add the Silverlight web part to the SharePoint website.Silverlight Project Properties 3.

Figure 59 . We will update the Silverlight web part added in the previous exercise to point toward the new Silverlight Charting control we have just made. Page 50 .SharePoint 2010 Developer Walkthroughs 5. Click the dropdown icon in the top right hand corner of the Silverlight web part and select Edit Web Part. Click the Configure button (you may have to scroll the window to the right to see the Configure button) and then enter /_layouts/ClientBin/SilverlightEmployeeContributionsGraph.Silverlight Web Part Properties 6.xap in the Silverlight Web Part dialog.

Page 51 . Click OK at the bottom of the Silverlight Web Part sidebar.SharePoint 2010 Developer Walkthroughs Figure 60 . 8.Silverlight Web Part URL 7. Click OK.

SharePoint 2010 Developer Walkthroughs 9.Finished Silverlight Chart Web Part Page 52 . The final web part will look like this: Figure 61 .

4. 3. 1. select File | New | Project. we will create a web part that renders and updates list data that is deployed as a Sandboxed Solution. 5. Open Visual Studio 2010 from Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010. expand the Installed Templates left-hand menu to Visual C# | SharePoint | 2010 | Empty SharePoint Project. 2. Task 1 – Create a Sandboxed Solution Project with a web part We will start by creating a standard Silverlight application project. Change the location to C:\SPHOLS\SPCHOL307\CS\Ex1\ Figure 62 . In the New Project dialog box. Name the project SBSolutionDemo.SharePoint 2010 Developer Walkthroughs Exercise 5 – Create a Web Part for a Sandboxed Solution In this exercise. From the menu.New Project Dialog Page 53 .

Ensure Visual C# | SharePoint | 2010 | is selected in the Installed Templates pane. change the local site to use for debugging to http://intranet. 7. In the SharePoint Customization Dialog. Leave the trust level for the SharePoint solution as Deploy as a sandboxed solution.com/. Right-click on the SBSolutionDemo project in the Solution Explorer and select Add | New item.contoso. Press Finish to continue. Press OK to continue. 12. In the Add New Item dialog. 11. 9. 10. select to add a new Web Part and name it SBWebPart. Visual Studio will create the new project and add the necessary files. Figure 63 .SharePoint 2010 Developer Walkthroughs 6. 8. Page 54 .SharePoint Customization Wizard Step1.

Add the following variables to the SBWebPart class: DropDownList _ddlProjects = new DropDownList().Web. TextBox _tbDueDate = new TextBox().HtmlControls.UI. Code Snippet: My Code Snippets | spchol307_ex1_webpart_namespaces 2. Task 2 – Add code to provide querying and rendering functionality 1. Add the following new methods within the SBWebPart class: Page 55 . Code Snippet: My Code Snippets | spchol307_ex1_webpart_variables 3. Press Add to add the web part to the project.SharePoint 2010 Developer Walkthroughs Figure 64 . Open SBWebPart.cs and add the following using statement after the other using statements: using System.Add New Item Dialog 13. TextBox _tbDescription = new TextBox().

} else { _tbDescription.Text = dueDate.Text = String.Lists["Projects"].SelectedValue != "-.Text = String. } /* Populate the text boxes with the selected project details */ private void GetProjectDetails() { EnsureChildControls().ToDateTime(spliProject["Due_x0020_Date"]).SharePoint 2010 Developer Walkthroughs protected override void OnLoad(EventArgs e) { base. int nProjectID = Convert.ToString().Current. SPListItem spliProject = pList.Web.Empty.Empty.IsPostBack) GetProjectDetails(). if (!Page. } } Code Snippet: My Code Snippets | spchol307_ex1_webpart_getprojectdetails Page 56 . _tbDescription.Text = spliProject["Description"]. _tbDueDate.Select a Project --") { SPList pList = SPContext. DateTime dueDate = Convert.SelectedValue).OnLoad(e).ToShortDateString(). if (_ddlProjects.GetItemById(nProjectID). _tbDueDate.ToInt32(_ddlProjects.

Controls.Add(panel). label.Style.CreateChildControls().Add(panel). panel = new Panel(). parent.Controls. bUpdateProject. Panel panel = new Panel(). label.Style. parent. _ddlProjects.Add("background-color".Add(_ddlProjects). parent. parent.Controls.Controls. parent. panel.Controls. panel. parent.Text = "Due Date".AutoPostBack = true. Panel parent = new Panel().ID = "ddlProjects".Add(panel). Replace the existing CreateChildControls method with the following code: protected override void CreateChildControls() { base.Controls.Add(panel). parent. panel. } Code Snippet: My Code Snippets | spchol307_ex1_webpart_createchildcontrols Page 57 .Add("width".Add(_tbDueDate).Style.Click += new EventHandler(bUpdateProject_Click). _ddlProjects. parent.Controls. "solid 1px Navy").SharePoint 2010 Developer Walkthroughs 4. panel = new Panel().Controls. panel.Controls.Add("border".Controls.Add(panel).Add(label).Add(_tbDescription). Button bUpdateProject = new Button().SelectedIndexChanged += new EventHandler(ddlProjects_SelectedIndexChanged). bUpdateProject. parent. Label label = new Label().Controls.Add(bUpdateProject).Add(parent).Add(label).Controls. "250px"). _ddlProjects.Text = "Update Project".Text = "Description". "#EEEEEE"). label = new Label(). panel = new Panel(). panel = new Panel(). panel. PopulateProjects().

EventArgs e) { EnsureChildControls(). SPListItem spliProject = SPContext.Text. 1.ID.GetItemById(nProjectID).Add(new ListItem(spli.Web. Right-click the SBSolutionDemo project and select the Package to create a . int nProjectID = Convert. } } void ddlProjects_SelectedIndexChanged(object sender.Update().wsp file.Current. 4.Web.Lists["Projects"].Items) { _ddlProjects.ToString())). Add the following methods below CreateChildControls: private void PopulateProjects() { SPList splProjects = SPContext.Items. Under the Galleries section select Solutions.Title. foreach (SPListItem spli in splProjects.Text. _ddlProjects.Current.ToInt32(_ddlProjects.SelectedValue). Open Internet Explorer and browse to http://intranet. EventArgs e) { GetProjectDetails(). Open the Site Actions menu and select Site Settings. spliProject["Description"] = _tbDescription. 2. spliProject. spli. } Code Snippet: My Code Snippets | spchol307_ex1_webpart_populateprojects Task 3 – Build and Deploy the Sandboxed Solution A sandboxed solution is deployed using the SharePoint web site. spliProject["Due_x0020_Date"] = _tbDueDate. } /* Update the current project */ void bUpdateProject_Click(object sender.com.Select a Project --"). Page 58 .contoso.Add("-.SharePoint 2010 Developer Walkthroughs 5.Items. 3.Lists["Projects"].

In the Upload Document dialog that pops up. Click OK to upload the SBSolutionDemo. Click Activate in the Solution Gallery . On the Solutions tab. set the Layout to Full Page. 12. Page 59 .Solutions Gallery 5.wsp file at C:\SPHOLs\SPCHOL307\CS\Ex1\SBSolutionDemo\SBSolutionDemo\bin\Debug\SBSolution Demo. 8. Click Create. Name the new Web Part Page SBSolutionDemoPage. Open the Site Actions menu and select More Options. And the Save Location to Shared Documents. 10. 6.SharePoint 2010 Developer Walkthroughs Figure 65 .wsp. The Sandboxed Solution web part is now ready to be used. 7. Select the Solutions tab. 11. select Upload Solution. select Web Part Page. Leave the Overwrite existing files box checked. Under the Page section of the Create dialog. browse to the .Activate Solution dialog. 9. Vertical.wsp to SharePoint.

Select Web Part and then under Categories Custom and under Web Parts choose SBWebPart. 16. click Page. 14.New Web Part Page 13.SharePoint 2010 Developer Walkthroughs Figure 66 . 17. Select the middle area of the new Web Part Page and then click the new Insert tab that appears in the top toolbar. 15. Click Create to create the new Web Part Page. Next. Click Add to add the Sandboxed Solution web part to the page. In the Ribbon.SBWebPart Page 60 . click Stop Editing in the toolbar Figure 67 .

Page 61 . Figure 68 .Windows Login Dialog 20. Select System Account in the toolbar at the top right hand side of the page and choose Sign in as Different User.SharePoint 2010 Developer Walkthroughs 18. close Internet Explorer. Click OK. The Sandboxed Solution web part is now ready to use. 19. For the User name enter andyj and for the password enter pass@word1. 21. When you are finished. Select different things from the dropdown to see.

SharePoint 2010 Developer Walkthroughs Figure 69 .The Sandboxed Solution Web Part Page 62 .

3. Page 63 . Open Visual Studio 2010 by going to Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010. and enter C:\SPHOLS\SPCHOL305\CS\Ex1 in the Location textbox.com and select Deploy as a farm solution. In Visual Studio 2010. create a new project by going to File | New | Project. Select the Visual C# | SharePoint | 2010 | Empty SharePoint Project project template. Then click Finish. 6.contoso. 4.SharePoint 2010 Developer Walkthroughs Exercise 6 – Creating an Activity for use in a SharePoint Designer Workflow This exercise shows how to create a custom workflow activity used by a SharePoint Designer reusable workflow and deploy them together as a single *. 1.WSP. Enter SPCHOL305Ex1 in the Name textbox. Click OK. It also shows how to import that workflow into Visual Studio 2010. Figure 70 . change the URL to http://intranet.New Project Dialog 5. 2. Task 1: Create and Prepare Project In this task a project you will create an Empty Project solution and use SharePoint user controls. In the SharePoint Customization Wizard.

5 Figure 72 .SharePoint Customization Wizard 7.Set .SharePoint 2010 Developer Walkthroughs Figure 71 . In Visual Studio 2010.NET Framework Version 3. Select the Visual C# | Workflow | Workflow Activity Library project template. 2. Task 2: Create a new Workflow Activity for use by the Reusable Workflow 1. Page 64 . Change the Framework to . Visual Studio will create the new SPCHOL305Ex1 project and add the necessary files. add a new project by going to File | Add | New Project.NET Framework 3.

In Solution Explorer. Page 65 . Switch to the Browse tab. Enter C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI in the File name textbox and hit Enter.SharePoint.WorkflowActions. 6.dll.SharePoint 2010 Developer Walkthroughs 4.SharePoint.dll and Microsoft. right-click the SPDActivityDemo project and select Add Reference. and click OK. Enter SPDActivityDemo in the Name textbox.New Project Dialog 5. and click OK. Select Microsoft. 7. Figure 73 .

2. Change the CreateDocumentLibrary base class from SequenceActivity to Activity.Add Reference Dialog 8. public partial class CreateDocumentLibrary : Activity 3.cs in the Solution Explorer and select Rename. as seen below. Add the following using statements at the top of the file under the existing using statements. 1.: Page 66 . Task 3: Add code to create a document library based on parameters passed to our activity. Rename Activity1.SharePoint 2010 Developer Walkthroughs Figure 74 . Right-click on the CreateDocumentLibrary. 9. Right-click on Activity1.cs file in the Solution Explorer and select View Code.cs to CreateDocumentLibrary.cs.

typeof(CreateDocumentLibrary).UrlProperty.Register("Url".UrlProperty))).Workflow. typeof(string).SetValue(CreateDocumentLibrary.SharePoint.  This will be the name of the DocumentLibrary created by the activity.WorkflowActions. using Microsoft. } } Code Snippet: My Code Snippets | spchol305_ex1_createdoclib_urlproperty 5.Visible )] [ValidationOption(ValidationOption.GetValue(CreateDocumentLibrary.SharePoint 2010 Developer Walkthroughs using Microsoft. Code Snippet: My Code Snippets | spchol305_ex1_createdoclib_namespace 4..SharePoint. [DescriptionAttribute("Url of base site")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility. Page 67 . new PropertyMetadata("")). Add a new DependencyProperty named UrlProperty to the CreateDocumentLibrary class.Optional)] public string Url { get { return ((string)(base. value). public static DependencyProperty UrlProperty = DependencyProperty.  This will be the location where the document library will be created. using Microsoft. Add a new DependencyProperty to the CreateDocumentLibrary class named DocLibNameProperty.SharePoint. } set { base.

} private void CreateDocLib() { using (SPSite sps = new SPSite(Url)) { using (SPWeb spw = sps. return ActivityExecutionStatus.DocumentLibrary).OnQuickLaunch = true. typeof(string). typeof(CreateDocumentLibrary). } } } Code Snippet: My Code Snippets | spchol305_ex1_createdoclib_execute Page 68 .Register("DocLibName".Optional)] public string DocLibName { get { return ((string)(base.Visible )] [ValidationOption(ValidationOption.RootWeb) { Guid ID = spw. spdl. spdl.Lists.Lists[ID].SetValue(CreateDocumentLibrary. Add the following code beneath your CreateDocumentLibrary constructor: protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { CreateDocLib().Closed.SharePoint 2010 Developer Walkthroughs public static DependencyProperty DocLibNameProperty = DependencyProperty. SPListTemplateType. [DescriptionAttribute("Used as doc lib name")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility. new PropertyMetadata("")). SPList spdl = spw. DocLibName + " Document Library".GetValue(CreateDocumentLibrary. } set { base.Add(DocLibName. } } Code Snippet: My Code Snippets | spchol305_ex1_createdoclib_doclibproperty 6.DocLibNameProperty. value).Update().DocLibNameProperty))).

snk. Figure 75 .Add Existing Item 2. 3.SharePoint 2010 Developer Walkthroughs Task 4: Configure activity for deployment. Add SPDActivityDemo. 1. Configure activity for a strong name. To the SPDActivityDemo project. Figure 76 .Signing 4. Right-click on the SPDActivityDemo project in the Solution Explorer and select Properties. check “Sign the Assembly. (Location at the start of this manual). and then select SPDActivityDemo. Click on the Signing tab. Build your project (CTRL-SHIFT-B) and fix any errors. Page 69 .snk from Resources folder.

Select Template\1033\Workflow in the Add SharePoint Mapped Folder dialog and select OK.SharePoint 2010 Developer Walkthroughs 5. Right-click on the SPCHOL305Ex1 project and click Add. Page 70 . SharePoint Mapped Folder Figure 77 .SharePoint Mapped Folder 6.

Select the XML File template and name the file SPDActivityDemo.ACTIONS then press Add. In the Solution Explorer.SharePoint 2010 Developer Walkthroughs Figure 78 . 8. expand the newly added Workflow folder. 9. 10. Right-click on the SPCHOL305Ex1 folder (if it exists) and select Delete. Page 71 .Add SharePoint Mapped Folder dialog 7. Right-click on the Workflow folder and select Add | New Item.

Add New Item dialog Page 72 .SharePoint 2010 Developer Walkthroughs Figure 79 .

CreateDocumentLibrary" Assembly="SPDActivityDemo. Build SPDActivityDemo Project Task 5: Add the SPDActivityDemo activity to be deployed with SPCHOL305Ex1. Click on the Advanced tab on the bottom of the designer Figure 80 .Advanced Package tab Page 73 . mscorlib" Direction="In" /> </Parameters> </Action> </Actions> </WorkflowInfo> Code Snippet: My XML Snippets | spchol305_ex1_workflowactions_xml 8."> <FieldBind Field="DocLibName" Text="Document Library Name" DesignerType="TextArea" Id="1"/> <FieldBind Field="Url" Text="Url of base site" Id="2" DesignerType="TextArea"/> </RuleDesigner> <Parameters> <Parameter Name="DocLibName" Type="System. Culture=neutral. 1.0. PublicKeyToken=a66e91d2ee2fa8f8" AppliesTo="all" Category="Labs"> <RuleDesigner Sentence="Document Library Name %1 to site %2. Double-click on the Package.SharePoint 2010 Developer Walkthroughs 7.ACTIONS with the following <?xml version="1. mscorlib" Direction="In" /> <Parameter Name="Url" Type="System. In the Solution Explorer expand the Package folder under the SPCHOL305Ex1 project.String.0. 3.0" encoding="utf-8"?> <WorkflowInfo> <Actions Sequential="then" Parallel="and"> <Action Name="Create Document Library" ClassName="SPDActivityDemo.0. Replace the contents of SPDActivityDemo.package file to bring up the Package designer.String. Version=1. 2.

Click OK Task 6: Configure a Feature using Feature Designer 1.0. Click the button under Safe Controls. When you have finished filling out the safe control details. In the Add Existing Assembly from Project Output dialog click the Source Project combo and select SPDActivityDemo\bin. press Enter to confirm them. Within Safe Controls add the following: Assembly Name: SPDActivityDemo. Figure 81 . 8. Right-click on the Features folder in the Solution Explorer under the SPCHOL305Ex1 project and select Add Feature.SharePoint 2010 Developer Walkthroughs 4.Add Existing Assebly from Project Output dialog 6.0. Culture=neutral.0. 5. Click the Add button and select Add Assembly from Project Output. Version=1. Page 74 . PublicKeyToken= a66e91d2ee2fa8f8 Name Space: SPDActivityDemo Safe: Checked Type Name: * 7.

SharePoint.SharePoint 2010 Developer Walkthroughs 2. Add a using statement to the top of the code: using Microsoft.Administration. Page 75 . 3. In Feature designer change the scope of the SPCHOL305Ex1Feature scope to WebApplication. Right-click on the SPCHOL305Ex1Feature feature in the Solution Explorer and select Add Event Receiver 2.Feature Designer Task 7: Add and code a Feature Receiver 1. Figure 82 . Right-click on Feature1 and rename it to SPCHOL305Ex1Feature.

Parent.SharePoint 2010 Developer Walkthroughs 3. modAuthorizedType.Value = "<authorizedType Assembly=\"SPDActivityDemo.Name = "AuthType". wappCurrent.Path = "configuration/System. Culture=neutral. } Code Snippet: My code Snippets | spchol305_ex1_spchol305feature_receiver 4.0. wappCurrent. Open SharePoint Designer 2010 by going to Start | All Programs | SharePoint | Microsoft SharePoint Designer 2010 Page 76 . Add the following code to your FeatureReceiver class declaration: public override void FeatureActivated(SPFeatureReceiverProperties properties) { SPWebApplication wappCurrent = (SPWebApplication)properties.Type = SPWebConfigModification.0.ComponentModel. PublicKeyToken=a66e91d2ee2fa8f8\" " + "Namespace=\"SPDActivityDemo\" TypeName=\"*\" Authorized=\"True\" />".Add(modAuthorizedType). Figure 83 .WorkflowCompiler/authorizedTypes". modAuthorizedType.Owner = "SPDActivityDemo".ApplyWebConfigModifications(). Build and Deploy the SPCHOL305Ex1Feature project by Right-clicking on the project name and selecting Deploy.EnsureChildNode.0.Workflow.Deploy Solution Task 8: Create a re-usable workflow using SharePoint Designer 1.WebConfigModifications.WebService.SPWebConfigModificationType.Feature. modAuthorizedType. modAuthorizedType. SPWebConfigModification modAuthorizedType = new SPWebConfigModification(). modAuthorizedType. " + "Version=1.

Figure 84 .SharePoint 2010 Developer Walkthroughs 2. Click on Sites and then Open Site.Sites menu button in SharePoint Designer 2010 If you are asked for credentials use: Username: Administrator Password: pass@word1 Page 77 .

com and select Open Figure 85 . Change Site name to http://intranet.SharePoint 2010 Developer Walkthroughs 3.Open Site dialog Page 78 .contoso.

Create Reusable Workflow Page 79 . Click the Reusable Workflow button and when prompted name the workflow SPDWorkflow and then click the OK button to create the reusable workflow. Figure 86 .SharePoint 2010 Developer Walkthroughs 5.

Figure 87 . Click the Actions button in the ribbon and scroll down to Labs and click Create a Document Library.SharePoint 2010 Developer Walkthroughs 6. Note: This is the activity we made in Visual Studio previously.Add Create Document Library Action Page 80 .

Click into Step 1.com as the URL of the base site. Select Current Item as the Data Source. on the ribbon. and Title as the value of Field from source. 8.Configue Workflow Action Page 81 . In the box next to Document Library Name click the Fx button. Figure 88 . Click Save.SharePoint 2010 Developer Walkthroughs 7. 10. Type in http://intranet. Then Press OK.contoso. Figure 89 .Lookup for String dialog 9.

Publish Workflow 12. Once saved click on Workflows in the left navigation.com Page 82 . Figure 90 . Wait for the workflow to publish. Click the workflow again beneath Reusable Workflow to bring up the workflow properties.Save As Template 14. Once saved click the Publish button in the ribbon. Open a web browser at http://intranet. Click Save as Template to save the .SharePoint 2010 Developer Walkthroughs 11.WSP file in the Site Assets Library SharePoint list. Figure 91 . 13.contoso.

Site Assets Library 16. Click on the SPDWorkflow dropdown menu and click Send To -> Download a Copy.SharePoint 2010 Developer Walkthroughs 15. Figure 93 .Download WSP Page 83 . Click Site Actions -> View All Site Content -> Site Assets Library. Figure 92 .

right-click on the SPCHOL305Ex1 solution in the Solution Explorer window Add | New Project.SharePoint 2010 Developer Walkthroughs 17.Save As Dialog Task 9: Import the reusable workflow into Visual Studio 1. Back in Visual Studio 2010. 2. Select the Visual C# | SharePoint | 2010 | Import Reusable Workflow project template. Page 84 . Save the WSP to a location that you can access in a subsequent step (like the Desktop) Figure 94 .

SharePoint 2010 Developer Walkthroughs 3. Page 85 . Figure 95 . Change the Name to SPDWorkflowImport. Click Ok.New Project Dialog 4.

com.SharePoint Customization Wizard Page 86 .SharePoint 2010 Developer Walkthroughs 5. Make sure the URL is http://intranet. Click Next. Figure 96 .contoso.

Click Next.WSP file to import. browse to the SPDWorkflow.SharePoint 2010 Developer Walkthroughs 6. Figure 97 . Page 87 .wsp file you saved previously. When prompted for the . Click Finish.SharePoint Customization Wizard 7.

SharePoint 2010 Developer Walkthroughs Figure 98 .SharePoint Customization Wizard Page 88 .

SharePoint 2010 Developer Walkthroughs 8.SharePoint Package Explorer Page 89 . Figure 99 . Double-click on Package in the SPCHOL305Ex1 project and add the Converted workflows feature to the Package.

build the solution and deploy the SPCHOL305Ex1 project. Select the project reference SPDActivityDemo and click OK.Add Assembly Reference 11. Change the workflow Name to SPDWorkflowFT Figure 101 .SharePoint 2010 Developer Walkthroughs 9. expand the Workflows\SPDWorkflowFT node.xml 13. Figure 100 . 12. Page 90 . Under the SPDWorkflowImport project. Open the Elements. Right-click on the SPDWorkflowImport project and select Add Reference 10. Save the project.Setting the imported workflow name 14.

Name the list Customers and press Create. Open List Settings Figure 102 .SharePoint 2010 Developer Walkthroughs Task 10: Associate the workflow with a list in SharePoint 1. 5. Click on Site Actions | More Options Select Custom List from the items list. 2. 3.contoso. Browse to http://intranet. 4. Under Permissions and Management click Workflow Settings.com.List Settings 6. Configure the list workflow settings as follows:  Select a workflow template: SPDWorkflowFT  Type a unique name for this workflow: Create Doc Lib for Customer  Select a task list: Tasks  Select a history list: Workflow History  Start options: Start this workflow when a new item is created Page 91 . 7.

Click OK 9. Navigate to the Customers list and select Items | New Item.SharePoint 2010 Developer Walkthroughs Figure 103 .Create New Item Page 92 .Workflow Settings 8. Figure 104 .

New Item Dialog 11.SharePoint 2010 Developer Walkthroughs 10. You can get the hands on labs that these walkthroughs were based on from http://MSSharePointDeveloper. Wait while a new document library of the same name should be created automatically. Enter Northwind as name of the new customer and press Save when the Customers – New Item dialog appears.com Page 93 . Walkthrough Summary In this walkthrough document you reviewed walking through six developer scenarios for SharePoint 2010. Figure 105 .