P. 1
SharePoint 2010 Developer Walkthrough Guide[1]

SharePoint 2010 Developer Walkthrough Guide[1]

|Views: 77|Likes:
Published by Alex Miller

More info:

Published by: Alex Miller on Jun 07, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/07/2012

pdf

text

original

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

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

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.SPCHOL200-Ex1 Project 11.SharePoint 2010 Developer Walkthroughs Figure 3 . Save the file. <properties> <property name="Title" type="string">SPLinqDemoTitle</property> <property name="Description" type="string">SPLinqDemoPart Description</property> </properties> Page 6 . Within the Solution Explorer. Figure 4 .webpart. expand VisualWebPart1 and open VisualWebPart1.Visual Web Part 12. Notice that Visual Studio also creates a Visual Web Part named VisualWebPart1.

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

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

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

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

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

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

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

Open Visual Studio 2010 by going to Start Menu | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.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 C:\SPHOLS\SPCHOL304\CS\Ex1 in the Location textbox. Click OK. 3. Task 1 – Create a Business Data Catalog Model project 1. Figure 16 . 2. Enter BDCEx1 in the Name textbox. Select the Visual C# | SharePoint | 2010 | Business Data Connectivity Model project template. and from the menu select File | New | Project. 5.New Project Dialog 4. Page 16 .

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

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

Highlight Identifier1 in the Entity designer and press F4 to open the Properties Grid. In the Solution Explorer.Entity1 entity 3. 2. Use the Properties Grid to rename Identifier1 to CustomerId and set its Type Name to System.Solution Explorer displaying BDCModel1. open the BdcModel1. 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 .Int32. In the designer select the Entity1 entity by clicking on the title. Figure 20 . Page 19 .bdcm in the BDC Designer.SharePoint 2010 Developer Walkthroughs Task 3 – Extend the BCS Metadata for the External Content Type 1.bdcm if the BDC designer isn’t already open. 4.

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

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

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

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

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

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

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

Change the Pre-Updater property on the id parameter to be True. Figure 35 . 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. Open the new Update method in the BDC Explorer window 22.SharePoint 2010 Developer Walkthroughs 21.Updating the Pre-Updater Field to True Page 27 .

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

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

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

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”). Figure 32 – Create new external list page Page 31 . 6.SharePoint 2010 Developer Walkthroughs In the Create dialog. Figure 31 – Create External List dialog 5. select External List and select Create. Enter My Contacts In the Name textbox.

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

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

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

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

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

SharePoint 2010 Developer Walkthroughs Figure 46 . 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.Silverlight Controls Toolbox 3. Figure 47 ..

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

SharePoint.GetItems(query).CamlQuery(). query. DueDate = Convert. Add the following code after the constructor: private void OnRequestSucceeded(Object sender.ToString() }). Page 39 . ClientRequestSucceededEventArgs args) { // this is not called on the UI thread Dispatcher. _projects = Projects. Description = li["Description"]. Code Snippet: My Code Snippets | spchol306_ex1_initializecomponent 11.Client.Load(_projects).Load(Projects).Lists.ToString()).Current. CamlQuery query = new Microsoft.GetByTitle("Projects").SharePoint 2010 Developer Walkthroughs ClientContext context = new ClientContext(ApplicationContext.ItemsSource = projects. context. context. context. 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>".Web. // must be on UI thread } Code Snippet: My Code Snippets | spchol306_ex1_methods This code initializes the SharePoint Silverlight client object model context (ClientContext).ViewXml = camlQueryXml.ToString().Add(new Project() { Title = li["Title"]. } private void BindData() { List<Project> projects = new List<Project>().Load(context. context. } dataGrid1.ToDateTime(li["Due_x0020_Date"].Web). foreach (ListItem li in _projects) { projects. List Projects = context.BeginInvoke(BindData). The results are converted into a list of Projects and bound to the Silverlight DataGrid control.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded). null).Url). 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.

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

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

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

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

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

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

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

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

Silverlight Web Part Properties 6. Page 50 . 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.xap in the Silverlight Web Part dialog.SharePoint 2010 Developer Walkthroughs 5. 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. Click the dropdown icon in the top right hand corner of the Silverlight web part and select Edit Web Part.

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

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

4.SharePoint 2010 Developer Walkthroughs Exercise 5 – Create a Web Part for a Sandboxed Solution In this exercise. 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. In the New Project dialog box. we will create a web part that renders and updates list data that is deployed as a Sandboxed Solution. 3. 2. From the menu. Task 1 – Create a Sandboxed Solution Project with a web part We will start by creating a standard Silverlight application project.New Project Dialog Page 53 . Change the location to C:\SPHOLS\SPCHOL307\CS\Ex1\ Figure 62 . Name the project SBSolutionDemo. 5. 1. select File | New | Project.

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

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

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

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

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

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

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

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

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

create a new project by going to File | New | Project. Page 63 . In Visual Studio 2010. change the URL to http://intranet. and enter C:\SPHOLS\SPCHOL305\CS\Ex1 in the Location textbox. 6. It also shows how to import that workflow into Visual Studio 2010. Select the Visual C# | SharePoint | 2010 | Empty SharePoint Project project template. Click OK. Figure 70 . 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.contoso. Enter SPCHOL305Ex1 in the Name textbox. 3.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 *.New Project Dialog 5. Then click Finish.WSP. 4. 2. 1. Open Visual Studio 2010 by going to Start | All Programs | Microsoft Visual Studio 2010 | Microsoft Visual Studio 2010.com and select Deploy as a farm solution.

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

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

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

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

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

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

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

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

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

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

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

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

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

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 .

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

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

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

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

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

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

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

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

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

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

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

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

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

List Settings 6. 7. 3. 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 . 4.SharePoint 2010 Developer Walkthroughs Task 10: Associate the workflow with a list in SharePoint 1. Name the list Customers and press Create. Under Permissions and Management click Workflow Settings. Browse to http://intranet. Click on Site Actions | More Options Select Custom List from the items list.com.contoso. 5. 2. Open List Settings Figure 102 .

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

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

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->