SharePoint 2010 Administration & Development
SharePoint 2010 Administration & Development
SharePoint 2010 Administration & Development
In his free time he focuses on writing articles and participating in Technology Forums including C# Corner (c-sharpcorner.com), MSDN Forums and dotnetspark.com. He has been the Member of the Month recipient for those sites and has won the Mindcracker MVP Award for 2011. In the academics, he holds a Bachelors Degree in Computer Science and a Masters in Business Administration. Presently he is working as a Freelance Consultant in his native India. His primary services include Development, Providing Architectural Decisions, Training Developers etc. He is presently running the blog: http://jeanpaulva.com/. Apart from Programming he loves music and researching on stocks.
www.jeanpaulva.com
Dedications
I would like to name the core people without whom I could not have achieved this: Sanoob K: He is presently working as a SharePoint Technical Consultant with Cognizant Technology Solutions. I am thankful to him for providing clarifications and editing the contents of this book. I am also inspired by his passion and confidence in SharePoint technology. Boby Thomas: He is presently working as a SharePoint Technical Consultant in an MNC firm based in UAE. He is deeply in love with SharePoint technology and I am thankful to him for keeping the interests alive. Neeb James: He is presently working as a .Net Developer in HCL Technologies. I am thankful to him for encouraging me in creating a book on SharePoint 2010. Praveen Kumar: He is Microsoft MVP and Chief Editor of c-sharpcorner.com. I would like to thank his good nature and time spent reviewing the book and publishing it on C# Corner.
Apart from that I would like to thank all my friends and ex-colleagues for supporting and guiding me in this venture of launching this book.
www.jeanpaulva.com
Disclaimer
The information contained in this ebook are collected and compiled over contents from Books and the Internet. The materials contained in this ebook are provided for general information purposes only and do not constitute legal or other professional advice on any subject matter. The author does not accept any responsibility for any loss which may arise from reliance on information contained in this ebook. Reproduction, distribution, republication and retransmission of material contained within this ebook are prohibited without the prior written permission of the author.
www.jeanpaulva.com
Contents
Introduction ....................................................................................................................................................... 8 Installation ....................................................................................................................................................... 13 New Features ................................................................................................................................................... 25 Basics ................................................................................................................................................................... 29 Central Administration ..................................................................................................................................... 30 Creating Web Application ................................................................................................................................. 34 Site Collections, Subsites, Top-Level Site............................................................................................................ 39 Configuring a Site ............................................................................................................................................. 44 Using Lists ........................................................................................................................................................ 50 Views, Lookups and Validations in List .............................................................................................................. 56 Enterprise Document Management .................................................................................................................. 63 Using Libraries ................................................................................................................................................. 67 Web Parts ........................................................................................................................................................ 70 SharePoint Designer ............................................................................................................................................ 79 SharePoint Designer 2010................................................................................................................................. 80 Creating a List Definition using SharePoint Designer ......................................................................................... 91 Programming ....................................................................................................................................................... 95 Starting Programming ...................................................................................................................................... 96 Project Items inside Visual Studio.................................................................................................................... 100 SharePoint Object Model ................................................................................................................................ 104 Lists and Event Handlers ................................................................................................................................. 109 List - Add, Edit, Delete using code ................................................................................................................... 116 Create List Definition using Visual Studio ........................................................................................................ 119 Create Document Library ................................................................................................................................ 123 Web Parts Programming ................................................................................................................................ 127 More on Web Parts ........................................................................................................................................ 135 Connected Web Parts ..................................................................................................................................... 138 LINQ and SPMetal .......................................................................................................................................... 145 Web Services .................................................................................................................................................. 151
www.jeanpaulva.com
Search ................................................................................................................................................................ 160 Search ............................................................................................................................................................ 161 Search Content Sources ............................................................................................................................... 164 Manage Search Scope .................................................................................................................................... 171 Create Crawl Schedule .................................................................................................................................... 176 Search Alerts .................................................................................................................................................. 182 BCS .................................................................................................................................................................... 184 Business Connectivity Services (BCS) ............................................................................................................... 185 BCS - External Database and Add/Edit/Delete Operations ............................................................................... 187 Workflows ......................................................................................................................................................... 197 Workflows...................................................................................................................................................... 198 Create Workflow using SharePoint Designer ................................................................................................... 202 Create Workflow using Visual Studio 2010 ...................................................................................................... 211 Deploying Workflow as WSP File..................................................................................................................... 217 Business Intelligence.......................................................................................................................................... 222 Introduction ................................................................................................................................................... 223 Maintenance ..................................................................................................................................................... 226 Backup and Restore ........................................................................................................................................ 227 Configure Email .............................................................................................................................................. 233 Quotas and Locks ........................................................................................................................................... 235 Site Usage Analysis......................................................................................................................................... 240 Managing the Search Service.......................................................................................................................... 244 Windows PowerShell ...................................................................................................................................... 248
www.jeanpaulva.com
Introduction
www.jeanpaulva.com
Introduction
SharePoint is a web application platform created by Microsoft. It is considered to be one of the most productive frameworks created by Microsoft in the last decade. SharePoint provides us the following feature support.
It provides us the following features: Sites Mobile Support Collaboration Document Management Content Management Enterprise Search Excel Services Extensibility Business Intelligence Visio Service
www.jeanpaulva.com
History
The SharePoint versions will be similar to that of office like SharePoint 2007, SharePoint 2010 etc. SharePoint started as a document sharing framework for Microsoft Office so that people can share their Word, Excel, PowerPoint documents. Later more features and extensibility was provided and SharePoint evolved as a highly productive component in the Microsoft Products Arena.
Versions
The latest version available is SharePoint 2010.
Advantages of SharePoint
So anybody could ask Why SharePoint instead of ASP.NET or other frameworks? For IT Professionals, SharePoint allows rapid creation of websites. It provides faster site creation with many builtin features like Content Management, Collaboration etc. These all possible at the cost of learning the skill: Administration of SharePoint. For Developers, SharePoint provides extensibility through programming. The SharePoint Object Model, WebParts etc. provides excellent start to developers in extending the features of SharePoint. Developers can take advantage of the builtin features extensions like Document Management, Search etc. The skill for attaining these would be: Programming SharePoint. SharePoint is one of the technologies where Administration and Programming (IT Professionals and Developers) are of core importance. If you are an Administrator then you can survive without programming skills. But if you are a developer you need both the Administration and Programming skills. As an example creation of a CRUD list in ASP.NET takes 8 hours of programming at least. In SharePoint we can achieve the same in just 5 minutes with high flexibility in extensibility.
Architecture
One of the major architectural changes in SharePoint 2010 is that the Shared Services Provider no longer exists. Now the services configuration is more flexible and we can add our own services to the platform called Service Applications. We can share the same service application across the farm and SharePoint provides instance management.
www.jeanpaulva.com
Services can be remotely managed and Central Administration provides this facility. There is a Default Group for services and all services are thus accessible to the entire farm as shown in the figure below.
Tools
The following are the important tools that could be used along with SharePoint to increase the productivity: Visual Studio SharePoint Designer Windows PowerShell
Visual Studio provides developer productivity through Web Part creation, custom content type addition, workflow creation, event listeners, deployment etc. SharePoint Designer helps in page layout, creating workflows, file management, workflow management etc. Windows PowerShell helps with automating tasks like site deployment, site backup and restore through scripts.
www.jeanpaulva.com
10
Editions
The following are the available editions of SharePoint 2010. Edition SharePoint Foundation SharePoint Server Standard SharePoint Server Enterprise Description Basic Free Edition having document management and collaboration features. Built on top of the SharePoint Foundation and includes business level functionalities. Built on top of Standard edition and targets large enterprises.
IIS Integration
It is worth knowing how SharePoint integrates with IIS (Internet Information Services). There are two modes of working for SharePoint: Classic Mode supported by ISAPI (older IIS Versions) Integrated Mode supported by Http Modules (ISS 7)
In the Integrated mode a particular Http Module will be configured for each SharePoint web application and it handles the HTTP requests to provide SharePoint rendering.
Hosting
The following are some of the hosting providers in SharePoint. Depending on the usage, the prices vary from starting from $100 per year.
http://www.webhostforasp.net/sharepoint-hosting/moss-plans.aspx http://www.ibeehosting.com/sharepoint-hosting.php
Additionally, Office 365 (new cloud member) supports SharePoint deployment as cloud enabled. Here higher productivity is possible by concentrating just on the application logic instead of configuring servers, setting up farms etc. SharePoint 2010 is supported and the billing will be on a usage basis.
http://www.microsoft.com/en-in/office365/sharepoint-online.aspx
References
http://sharepoint.microsoft.com/en-us/buy/pages/editions-comparison.aspx
www.jeanpaulva.com
11
Summary
In this chapter we saw a quick introduction to SharePoint, history, editions, versions and features. In the next chapter we will proceed with installation.
www.jeanpaulva.com
12
Installation
In this chapter we can proceed with the installation of SharePoint 2010. Depending on your operating system and edition of SharePoint, the installation files vary.
Editions
The following editions are available for SharePoint 2010: Foundation Standard Enterprise
Software Pre-Requisites
The following are the software pre-requisites: 64-bit Operating System (Windows 7 / Windows Vista SP2 / Windows Server 2008) .Net Runtime 3.5 SP1 ASP.NET 3.5 with SP1 SQL Server 2008 R2 PowerShell 2 Visual Studio 2010
Note: 64-bit Windows 7 can be installed on a 32-bit computer. For production server the operating system should be Windows Server 2008 and SharePoint Standard/Enterprise.
Download
There are multiple ways for installing SharePoint 2010. Three of them are: 1. You can download a standard trial version from the following link:
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=9344 2. Use the Easy Script to set up a development machine with SharePoint 2010; see: http://www.microsoft.com/download/en/details.aspx?id=23415 This option takes several hours depending on your internet connection speed. 3. Use the Virtual Hard Drive (VHD) option to have a preconfigured environment for learning; see: http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=27417
www.jeanpaulva.com
13
Installation
Download the file specified in option 1. After the download execute the file SharePointServer.exe
Use the Install software prerequisites menu item from the Install category. As the installer check for Windows Server 2008 operating system you will get the following error.
www.jeanpaulva.com
14
www.jeanpaulva.com
15
www.jeanpaulva.com
16
Execute the command file and the installation will show the previous screen. First use the Install Prerequisites option to install the required components. Next use the Install SharePoint Server option to continue. Now the following new screen is prompted.
Enter the following key for trial edition: VK7BD-VBKWR-6FHD9-Q3HM9-6PKMX. On pasting the key is automatically validated and the Continue button becomes enabled. Click the button to continue.
www.jeanpaulva.com
17
www.jeanpaulva.com
18
In the above screen use the Standalone option to install all the SharePoint components in your machine. Now the installation starts..
www.jeanpaulva.com
19
Waiting for around 10 minutes, the installation will be completed; click the Close button.
Configuration
If you checked the Configure option from the previous screen then you will get the following Configuration wizard. Click the Next button to continue..
www.jeanpaulva.com
20
The wizard will perform activities like configuration of the database, registering services, sample data creation etc. It will take almost 10-15 minutes for completion. On completion you will see the following dialog box.
www.jeanpaulva.com
21
Post Installation
After the installation you will be able to see the following start menu item:
www.jeanpaulva.com
22
Open the SharePoint 2010 Central Administration item and you will get the following prompt:
Enter the machine user name and password and proceed by clicking the Ok button.
www.jeanpaulva.com
23
If you can see the above screen then you are ready, you have a successful installation.
References
http://msdn.microsoft.com/en-us/library/ee554869.aspx
Summary
In this chapter we saw the trial installation of SharePoint 2010. The above installation is useful for evaluating the SharePoint features and setting up a developer machine.
www.jeanpaulva.com
24
New Features
In this chapter we can explore the new features of SharePoint 2010. Some of the new features of SharePoint 2010 are: Ribbon UI Status Bar Dialogs Branding and Theming Multilingual User Interfaces Inline Editing Developer Dashboard Silverlight Web Part Service Applications
For exploring the features please open the SharePoint 2010 default web application. For example: http://yourmachinename
Ribbon UI
The Ribbon User Interface can be considered to be a major UI change in SharePoint 2010. It makes it similar to the Microsoft Office family of products. The advantages are user friendliness, easier access, categorized menus etc.
Status Bar
SharePoint 2010 provides a Status Bar which is below the Ribbon UI. It is not the Browser status bar. The Status Bar is configurable through pages.
www.jeanpaulva.com
25
Inline Editing
SharePoint 2010 allows the List items to be edited inline. This is without the use of an additional dialog with Ok and Cancel buttons. For enabling this we have to use the Modify View option in List Settings and choose an Inline Editing enabled checkbox.
New Dialogs
The dialogs are enhanced in SharePoint 2010. Some of the examples are given below. New List and Library Dialog, Status Dialog:
www.jeanpaulva.com
26
You can, at anytime, change the Site theme using the Site Settings > Look and Feel > Site theme option.
www.jeanpaulva.com
27
Developer Dashboard
The developer dashboard is a new feature in SharePoint 2010 which can be used for debugging and tracing purposes. It provides performance related information to developers. It is by default turned off and can be enabled by using PowerShell or the StsAdm tool.
Service Applications
In the older version SharePoint 2007 there exists Shared Services Providers (SSP). This feature no longer exists in the SharePoint 2010 version and only Service Applications exists. The service applications like Search and Excel Services are unboxed and run independently.
References
http://msdn.microsoft.com/en-us/library/ee557323.aspx http://weblogs.asp.net/soever/archive/2009/10/20/sharepoint-2010-spc09-ssp-is-dead-longlive-service-applications.aspx
Summary
In this chapter we have explored the new features of SharePoint 2010.
www.jeanpaulva.com
28
Basics
www.jeanpaulva.com
29
Central Administration
In this chapter I would like to experiment with Central Administration for web applications.
In summary the Central Administration is the Administrator/Developer tool. It is used to manage the websites for other users.
On executing the command you will see the following screen in the browser (ensure you provided the credentials properly by default it will be the system username and password).
www.jeanpaulva.com
30
Now we are ready to explore web applications. Before that we need to go through the hierarchy of web applications, sites etc.
www.jeanpaulva.com
31
Hierarchy
The following is the hierarchy of SharePoint Farms, Web Applications, Site Collections, Sites, Lists and Documents.
The following is the description of the items in the image shown above: Server Farm: Server Farm contains multiple components like SharePoint server and Database server providing multiple Web Applications spanned over multiple machines. For development machines one single machine can support all the components. Web Application: A Web Application contains multiple Site Collections. This could be equivalent to an ASP.NET application. Site Collection: Site Collection contains multiple Sites. Site: Site contains Lists, Documents etc.
www.jeanpaulva.com
32
To view the web applications, click on the Manage web applications link under the Applications Management category. You can see that in the following screen:
References
http://www.dummies.com/how-to/content/sharepoints-site-hierarchy-model.html
Summary
In this chapter we saw the SharePoint hierarchy and the creation of a WebSite and a SiteCollection.
www.jeanpaulva.com
33
IIS Manager
Each web application inside SharePoint is configured along with IIS (Internet Information Services). Use the inetmgr command to view the IIS Manager as shown below:
The applications highlighted above represent the SharePoint port 80 web application and Central Application web application.
www.jeanpaulva.com
34
In the window that appears you will see 2 items, the default web site and the Central Administration site. The default web site is created during SharePoint installation. The Central Administration is the website which is used by Administrators it contains items to manage existing web sites, create a new website and other tasks. Click on the New button in the Ribbon UI.
www.jeanpaulva.com
35
Here you can set the following options: IIS Web site Application Pool Security Database Name
Leave the default values except in the Security Account in Application Pool.
www.jeanpaulva.com
36
Press the Ok button and you will see the following busy screen. Web Application creation is a time consuming process and may take several minutes.
After waiting for a while you will see that the new web application is created.
www.jeanpaulva.com
37
Summary
In this chapter we have seen how to create a new web application using Central Administration. Please note that each web application created is created inside IIS for the machine.
www.jeanpaulva.com
38
Note
All the content of a site collection is stored inside the configured SQL Server database. We can add up to 15000 (configurable value) site collections inside the content database. Often the term sites is used to represent site collections.
www.jeanpaulva.com
39
We are going to create a site collection for a group of Microsoft .Net users in the company. Click on the Create site collections link as shown above. You will get the following screen:
www.jeanpaulva.com
40
www.jeanpaulva.com
41
Enter the details in the highlighted areas. The description of which is given below: Item Web Application Title Description Url User Name Description Choose your web application. By default there is only one web application. Title for your site collection, appears in browser Description of your site Enter the URL suffix. This URL can be shared for the group of users. The users who are allowed to access this site collection. Use the Check Names option to auto complete the qualified user name after entering the user name.
On clicking the Ok button and waiting for a while the new site collection will be created. A message appears like shown below.
Click the Ok button to return to Central Administration. Now you are ready with the new site collection. You can share the URL between the intended users. On my machine the URL was: http://appes-pc/my/personal/dotnet/default.aspx. When the URL was opened in the browser the following page was displayed:
Now the users of the site collection can create new sites inside this site collection. We can explore that in the next chapters.
www.jeanpaulva.com
42
References
http://technet.microsoft.com/en-us/library/cc263094.aspx
Summary
In this chapter we have explored Site Collection Creation. Please note that an ordinary user does not have permission to create top level sites.
www.jeanpaulva.com
43
Configuring a Site
In the previous chapter we saw how to create a Site Collection with Lists and Libraries inside it. In this chapter we can explore how to configure a site. Prior to proceeding please open the site collection we created in the previous chapter. For example: http://appes-pc/my/personal/dotnet/default.aspx
This is the main page displayed when accessing the URL. We can customize the page by adding more content to it. For this, use the Site Actions > Edit Page option from the left side menu.
www.jeanpaulva.com
44
We can add Web Parts to the section. The Web Parts can be used to display: Image HTML Content Silverlight Applications etc.
For the time being, we are adding a Content Editor Web Part.
www.jeanpaulva.com
45
Click the Add button to add the Web Part to the page.
Use the highlighted area to add new content to the Web Part. You can add your own contents about the site. You can use the Formatting Ribbon for text formatting, Page Ribbon for inserting Hyperlinks etc. After the editing is finished use the Page Stop Editing button.
Site Permissions
Another important configuration feature is Site Permission. Using Site Permission we can enable and disable site users for a particular site collection or site. Use the Site Settings > Site Permissions menu item to get the screen.
www.jeanpaulva.com
46
On clicking the Site Permissions item, you will see the following screen:
www.jeanpaulva.com
47
You can select each group and add or remove the users or user groups inside it. In this way the site read/write permissions are managed. You can always create a new group using the Create Group menu item from the ribbon. There is also a special group called Site Collection Administrators accessible from the ribbon.
Site Settings
We can use the Site Settings screen to manage the advanced features of the site like: User Permissions Site Content Types Site Columns Regional Settings Workflows Themes Site Features Search Settings
The Site Settings can be accessible from My Site > Site Settings menu item.
www.jeanpaulva.com
48
References
http://technet.microsoft.com/en-us/library/ee656740.aspx
Summary
In this chapter we have explored Configuring a site in SharePoint 2010.
www.jeanpaulva.com
49
Using Lists
In this chapter we can focus on Lists in SharePoint. We can create multiple lists in SharePoint 2010. The limit can be configured through Central Administration. To begin use our site collection URL to open the page.
Creating a List
Now we can start by creating a List. As mentioned in the previous chapter a SharePoint List is a collection of items. We can specify columns as metadata for the List. We can create a List based on existing templates or from scratch. Click on the Lists option from the left side and click the Create button. The following dialog box appears:
www.jeanpaulva.com
50
Choose one of the templates, for example Announcements. Enter the name for your list and Click the Create button. The new List will be created as shown below:
You can use the Items or List ribbons to add an item, or modify the view.
www.jeanpaulva.com
51
Enter the details for the Announcement and click the Save button. Your new item will be displayed as below.
www.jeanpaulva.com
52
Deleting a List
We might need to delete an existing List entirely. In this case do the following. 1. Open the List 2. Click the List ribbon menu item
Now the list will be deleted from the site. Note: In a list there is always an ID column which is hidden. So while creating custom columns for the list, the name ID will be reserved. It is case-sensitive too.
Indexes on List
SharePoint allows us to manage large amounts of data. The data are actually stored inside SQL Server database tables. So we can suggest the Indexing feature of tables to allow faster fetching of records. We can use the Indexed Columns feature of any List to provide Indexing. Click on the List Settings > Indexed Columns link to open an Indexed Columns page.
www.jeanpaulva.com
53
Use the Create a new Index in a subsequent page. Choose the column for Indexing and click the Ok
button to the create Index.
Now the Index will be successfully created and shown in the Index details of the List.
In real-world scenarios Indexes provide high leverage in data loading and manipulations.
References
http://office.microsoft.com/en-us/sharepoint-foundation-help/create-or-delete-a-listHA010377306.aspx
www.jeanpaulva.com
54
Summary
In this chapter we have explored Lists and Indexes in SharePoint. The list provides an interface to store related entities and a library provides a document storage facility. There are many more templates to explore in the List section.
www.jeanpaulva.com
55
Views
We can associate a View with a List. Views provide a different representation of the existing information. If a List has the columns Name and Country we can create a View for the List with the county India. Here we are experimenting with custom column creation as well. For this create a new List with Custom List as the template.
Now there are 2 records with India and Other as country. From the List ribbon item and click Create View button.
www.jeanpaulva.com
56
In the page that appears, enter the name for the view as Contacts in India. Scroll down and in the Filter section filter Country as equal to India.
Click the Ok button to create the View. Now you can see the view only lists one record.
www.jeanpaulva.com
57
This concludes our View creation. Note: Views can be used to show grouped data, filtered data etc. based on the existing Lists items. In this way it is similar to the database Views which operate on tables. In SharePoint the contents are stored in a SQL Server database.
Lookups
A column in a List can integrate with another List column. For example we have 2 lists. Doctor List Title Name Qualification Patient List Title Name Address Doctor (Referring to the Doctor.Name column) Here the Patient List is referring to the Doctor List through the Doctor column which is acting as a Lookup column. To do that create a custom list named Doctors with Name and Qualification as columns. Note: The Title column will already be there, renaming or deleting can be done through the List Settings screen. Now create a new list named Patients using the Custom List template. Add the properties Name, Address and Doctor. For the column Doctor choose Lookup field.
www.jeanpaulva.com
58
Choose the highlighted list items as shown in the screen above. The Lookup field is required to fetch data from other Lists. We need to specify the List and Column for Lookups. After setting the Lookup properties click the Ok button. Now add some data to the Doctors list as shown below:
Now use the Add new item for the Patients List. You will be able to see the Doctor lookup field auto populated from the Doctors List.
www.jeanpaulva.com
59
Enter the details and click the Save button. You are ready with the Patient with Doctor as Lookup value.
So this concludes our experiment with Lookup values. In real-life scenarios we will end up with multiple Lookup values and validations. The Lookup values are implemented using Relationships. It is similar to the foreign key relations of a Relational Database Management System like SQL Server.
Validations
We can add validations for the columns. Now we can start experimenting with them. Here we are starting with a List of Employees. The columns are: Title Name Age
www.jeanpaulva.com
60
Make sure that the Age column is in the range 18 to 100. Any out-of-range values should populate the error message Invalid Age Please enter a value between 18 and 100!. Create a List from the Custom List template and name it Employees. Add the custom columns Name and Age. For the Age column make the type Number. In the Column Validation section at the bottom enter the following properties: Formula: =AND(Age>=18,Age<=100) User Message: Invalid Age Please enter a value between 18 and 100!
www.jeanpaulva.com
61
Click the Ok button to continue. Now the List is ready with Name and Age columns. Try to add a new item into the list with an invalid age (age = 11 for example):
You will see that the error message for invalid Age is shown. This concludes our experiment with validations. In real-world scenarios more complex validations need to be performed. For reference on the formulas you can use the link provided in the References section of this chapter.
References
http://office.microsoft.com/en-us/windows-sharepoint-services-help/examples-of-commonformulas-HA001160947.aspx
Summary
In this chapter we have learned about Views, Lookups and Validations. This knowledge is needed in building real-world record management systems using SharePoint 2010.
www.jeanpaulva.com
62
The main features supported by SharePoint 2010 are: 1. 2. 3. 4. 5. 6. 7. 8. Metadata Versioning Alerts Workflows Check Out Search Co Authoring Auditing
Versioning
SharePoint supports public, major and minor versioning support. To enable versioning use the Library Settings > Versioning settings option.
www.jeanpaulva.com
63
Metadata
We can store information about the library items as Metadata using Columns. For adding Metadata for any library item use the Library Settings > Create Column option.
www.jeanpaulva.com
64
Using Enterprise Keywords we can tag a particular document. As they are indexed they are searchable and provide meaningful organizational capabilities.
Types of Libraries
SharePoint 2010 provides various types of built-in document libraries. Library Type Document Library Asset Library Connection Library Report Library Slide Library Picture Library Form Library Description For all document types For images, video files Storing connection files KPI (Key Performance Indicator), BI files PowerPoint Slide files Picture files InfoPath Form files
Document ID Service
The document ID feature creates document identifiers that can be used to retrieve items independent of their current location. The document ID service is responsible for providing the Document ID feature. When a document is added to the collection SharePoint assigns the Document ID to it. The administrator needs to configure the Persistence setting of Document ID. To enable this feature use Site Actions > Site Settings > Site Collection Features item.
www.jeanpaulva.com
65
Document Set
Document Set is a new feature in SharePoint 2010. It is similar to a zip file and a good solution while working with a group of files. While working with a project, people usually needed a set of files instead of a single file. So the Document Set feature is really useful once we know how to use it. To enable this feature use Site Actions > Site Settings > Site Collection Features item.
Click on the Activate button to start the service running. The creation of documents and document sets are discussed in a later chapter.
References
http://msdn.microsoft.com/en-us/library/ee559302.aspx http://office.microsoft.com/en-us/sharepoint-server-help/introduction-to-document-setsHA101782466.aspx
Summary
In this chapter we have explored the Document Management Features supported by SharePoint. The versioning, check out and co-authoring features provides the SharePoint end users a great tool in hand.
www.jeanpaulva.com
66
Using Libraries
In this chapter we can focus on Libraries, which are the document management repositories in SharePoint 2010. The previous chapter should have given a good overview of the Document Management features of SharePoint.
Creating a Library
Now we can create a library. A library represents a collection of documents. For example a Document library, PDF library etc. Click on the Libraries item from the left pane.
www.jeanpaulva.com
67
Select the Library option from the left pane, then choose Document Library from the middle pane and enter the name on the right pane. Click the Create button to continue. You will get the progress screen as shown below:
Click the Add document button to start adding documents to the library.
www.jeanpaulva.com
68
Choose a document and click the Ok button. Your new file will be listed in the document library as shown below.
Deleting a Library
For deleting a particular library, the steps are similar to deleting a list. Open the library, click the Library Settings option and use the Delete the document library option as shown below.
Summary
In this chapter we have explored Libraries in SharePoint. There are many more templates to explore in the Library section.
www.jeanpaulva.com
69
Web Parts
Web Parts are rectangular areas of HTML content. We can provide information to the users using Web Parts. The history of Web Parts starts from year 2000 in the name Digital Dashboard. Later it evolved as Web Parts and includes support in SharePoint Designer and Visual Studio. We can use the existing Web Parts or build custom Web Parts for SharePoint. SharePoint 2010 contains builtin Web Parts and provides custom Web Part integration facilities. Web Parts provides a set of controls to display, modify, and configure the contents.
Adding a WebPart
For starting with open our site collection using the URL.
www.jeanpaulva.com
70
We can start by adding an image WebPart to the main page. Click on the top-left menu Site Actions > Edit Page option.
On the appearing screen below, click on the first Add a Web Part button.
www.jeanpaulva.com
71
Select Media and Content from the first pane and Image Viewer from the second pane and click the Add button. Now the Web Parts are added to the page.
Use the open the tool pane option and enter an image URL inside it, then click the Apply button.
www.jeanpaulva.com
72
Now click the Stop Editing button from the ribbon menu.
Now you are ready with the main page with an image as shown below.
www.jeanpaulva.com
73
www.jeanpaulva.com
74
Then use the Delete option again from the Web Part context menu.
There we can locate the custom List created inside SharePoint. The List Web Part allows us to add the List to other sites through Web Parts.
www.jeanpaulva.com
75
www.jeanpaulva.com
76
On clicking the preceding link you will see the page as shown below:
www.jeanpaulva.com
77
We can create our custom Web Part and deploy it to the SharePoint server. These topics are discussed in advanced chapters. The Web Parts will have the extension .dwp which is short for Dashboard Web Part.
References
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpart.aspx
Summary
In this chapter we have explored the Web Part feature, Adding/Editing/Deleting Web Parts, Silverlight Web Part, Web Part Galleries etc. The key points of Web Parts would be: A rectangular area of HTML content Flexible piece of Functionality Users can manage adding/deleting Web Parts Custom Web Part creation is possible
www.jeanpaulva.com
78
SharePoint Designer
www.jeanpaulva.com
79
Features
Some of the cool features of Designer are: It is Free WYSIWYG (What You See Is What You Get) Editor No Coding Required Useful for Administrators as well as Developers Workflow Creation Editing of Site, Styles Possible using Designer Branding Form Customizations Visio Integration InfoPath Forms Data Source Configuration Manage Site Permission, Site Columns etc. BCS (Business Connectivity Configuration) Create Content Types ASP.NET, XML, XSLT, RSS, XHTML support SOAP and REST support Administrator can restrict the use of Designer on sites
Version
The version compatible with SharePoint 2010 is SharePoint Designer 2010. The previous version of designer was SharePoint 2007. The ancestor of SharePoint Designer is Microsoft FrontPage which was a web editor of the times.
Download Link
You can use the following links to download the 32-bit and 64-bit versions of Designer 2010:
http://www.microsoft.com/download/en/details.aspx?id=16573 http://www.microsoft.com/download/en/details.aspx?id=24309
www.jeanpaulva.com
80
You can change the following options on the preceding screen: Enable / Disable SharePoint Designer for the Site Enable / Disable detaching page from the site definition Enable / Disable customizing master pages Enable / Disable managing of web site URL feature
www.jeanpaulva.com
81
Use the Open Site button and you will get the following dialog:
www.jeanpaulva.com
82
Enter the site URL and click the Open button. Enter the credentials in the dialog that appears. You will get the site opened in the main Designer window as shown below:
The left side pane shows various features of the site like: Lists and Libraries Workflows Site Pages Site Assets
We can select the item from the left pane and the properties are displayed on the right side.
Now select the Lists and Libraries item from the left pane. You will be able to see a list named contacts.
www.jeanpaulva.com
83
Click on the contacts item and you will get the properties of it.
You will see 3 forms on the Forms pane which are described below: Form DispForm.aspx EditForm.aspx NewForm.aspx Description Used to display the item details (View command) Used to edit the item details (Edit command) Used to add a new item (New command)
Now we can add a new page and apply the Display (View command) to it. Click on the New button from the Forms pane. Enter the following details in the appearing dialog.
www.jeanpaulva.com
84
Click the Ok button to continue. Now the new form is added and acts as the default View form. You can try changing the color of the form labels, deleting some rows, adding a hyper-link, custom formatting etc. After the changes click the Save button and you are ready to check the edited page inside SharePoint. (Use the Refresh button to get the controls.) Inside the SharePoint site, add a new contact and use the View Item command for the newly added item. You will see the following screen:
www.jeanpaulva.com
85
Note
Please make sure that you are editing only the new custom form. Changing the SharePoint pages may create problems and hence is not advisable for new users.
www.jeanpaulva.com
86
Click on the v4.master item and it will be opened as shown below. Use the Edit File option from the page that appears.
www.jeanpaulva.com
87
You can modify the control properties in the window that appears. There is an option on the bottom of the Designer to switch to the Code View from the Design View.
www.jeanpaulva.com
88
You can see in the preceding image that the Manage Styles properties window is in the bottom -right end of the designer.
Right-click on the item and use the Edit Item menu item. There you can change the style of the particular item. Any changes will be reflected in the SharePoint site upon saving.
References
http://community.bamboosolutions.com/blogs/sharepoint-2010/archive/2010/04/01/new-features-insharepoint-designer-2010.aspx http://blogs.msdn.com/b/sharepointdesigner/
www.jeanpaulva.com
89
Summary
In this chapter we have explored the SharePoint Designer. The Page Customization and Master Page Editing facilities using the Designer were explored.
www.jeanpaulva.com
90
From the ribbon menu, use the Custom List button; see:
In the dialog box that appears enter the Name and Description for the List.
www.jeanpaulva.com
91
Click the OK button to continue. The new List Definition will beadded as shown below:
Now use the Edit Columns button from the ribbon menu.
You can see the default Title column is already in the list. Add the following 2 columns using the Add New Column button from the ribbon menu:
www.jeanpaulva.com
92
Now you are ready with the new List Definition. Go back to SharePoint inside the browser and you will see the new List there:
You can try adding a new item and the dialog window shows the columns we added.
www.jeanpaulva.com
93
Click the Save button and this concludes our List Definition creation using SharePoint Designer.
Summary
In this chapter we have experimented with List Definition creation using the SharePoint Designer. The Designer provides an easier way for Administrators.
www.jeanpaulva.com
94
Programming
www.jeanpaulva.com
95
Starting Programming
In this chapter we can start with the programming part of SharePoint 2010. Through programming we are able to get more control and flexibility over SharePoint. We can use Visual Studio to do the programming part with the support of the SharePoint server side object model library. Some of the advantages gained through programming SharePoint are: Server Object Model to Iterate over Lists and Libraries Content Type Creation Web Part Creation WorkFlow Creation Assembly Signing Business Data Connectivity Model Creation Site Definition Creation Automated Backup and Restore
Visual Studio
Here we are using Visual Studio 2010 to work with SharePoint 2010. You can use a 32-bit or 64bit version of Visual Studio 2010.
This tool helps with custom templates and automatic Web Part deployment to the SharePoint server and other integration facilities.
Download
You can download the tool from the following link:
http://sharepointdevtools.codeplex.com/ According to the documentation the tool provides extensions to four core areas:
1. 2. 3. Environment Exploration Templates
www.jeanpaulva.com
96
4. Deployment
After installing the tool, start a New Project in Visual Studio and you will be able to see the following SharePoint project categories:
For begin, select the Empty SharePoint Project template and click the Ok button. The following site dialog box will be shown.
www.jeanpaulva.com
97
Enter your site URL, leave the other options as unchanged and click the Finish button. Now the Solution Explorer will look like the following:
www.jeanpaulva.com
98
Try building the project and if the build succeeds your Visual Studio is ready for SharePoint 2010 development. We can explore the programming areas in the upcoming chapters.
References
http://msdn.microsoft.com/en-us/magazine/ee309510.aspx
Summary
In this chapter we have explored the programming part of SharePoint 2010. Using Visual Studio we can gain control over the SharePoint sites and features. In the upcoming chapters we can play around with the object model and features.
www.jeanpaulva.com
99
This template contains the Features and Package files needed for deployment.
www.jeanpaulva.com
100
Site Definition
This project contains a site definition folder which includes the default aspx page for the site, site component file, site configuration file etc.
List Definition
This project template contains the List templates. It includes content type, list templates, event receivers etc.
Modules
www.jeanpaulva.com
101
The module template is used to include the manifest xml file and the notes about a project. It is not the same as a Module in Visual Basic.
Content Type
Content Types are information on data. For example a Task can be declared as a Content Type. Later a Task can be used inside a List. Apart from the custom properties, we need to explore the other topics related to SharePoint development using Visual Studio.
Sandboxed Solutions
A Sandboxed Solution is a new concept in SharePoint Foundation that allows the users to upload their own code solutions. The Sandboxed Solutions are viewable and validated by Administrators through the Solutions Gallery. The Solutions Gallery can be accessed from Site Actions > Site Settings > Solutions.
We can view the resource usage of solutions and manage the quota from the Solutions Gallery.
References
www.jeanpaulva.com
102
http://msdn.microsoft.com/en-us/library/ee231554.aspx http://msdn.microsoft.com/en-us/library/ee539083.aspx
Summary
In this chapter we have explored the Project Items inside Visual Studio and had an overview of the various aspects of SharePoint development. In the upcoming chapters we can jump into coding solutions for SharePoint 2010.
www.jeanpaulva.com
103
Namespace
The Server Object Model classes are residing in the Microsoft.SharePoint assembly. The general classes are available inside Microsoft.SharePoint namespace and the administration classes inside Microsoft.SharePoint.Administration namespace.
Core Classes
The Following are the important classes and their corresponding SharePoint items. Class SPFarm SPServer SPSite SPWeb SPControl SPList SPDocumentLibrary SPContentType SPUser SPException SharePoint Item Farm Server Site Collection Web site Control List Document Library Content Type User SharePoint Exception
Programming
Now we can begin to experiment with some of the preceding classes. To begin we can create a SharePoint Console Application. Use the New Project > SharePoint > Console Application project item.
www.jeanpaulva.com
104
If you receive any build errors regarding namespace, change the Project Properties > Target to .Net Framework 3.5.
Now try building the application and it should work fine. You will see the following output:
www.jeanpaulva.com
105
Please note the usage of Title and Name properties and the GetFormattedValue() method.
www.jeanpaulva.com
106
SPControl
The SPControl class acts as the base class when developing server controls. It resides in the namespace Microsoft.SharePoint.WebControls. SPControl provides static methods that return a reference to the current site, web, web application or module. The methods are:
SPControl.GetContextSite() SPControl.GetContextWeb() SPControl.GetContextWebApplication() SPControl.GetContextModule()
SPException
The SPException class can be used to handle an exception inside a try catch block. It represents the exceptions thrown by the server object model.
try { // Code here } catch (SPException ex) { // Handle Exception }
SPUser
The SPUser class can be used to access user information for a SharePoint site. Enter the following code to get the number of users and their names.
using (SPSite site = new SPSite("http://appes-pc/my/personal/dotnet")) {
www.jeanpaulva.com
107
using (SPWeb web = site.OpenWeb()) { foreach (SPUser user in web.AllUsers) Console.WriteLine("User: " + user.Name); } }
On running the code you will see the results based on your machine users, as in:
Note
You can add a new list item or library item using the Items.Add() method. For updating and deleting use the item.Update() and item.Delete() methods respectively. More code coverage on these areas will be provided later.
References
http://msdn.microsoft.com/en-us/library/ms473633.aspx http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spcontrol.aspx http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx
Summary
In this chapter we have explored the SharePoint Object Model and some basic coding examples with List and Library. The advanced coding examples will be provided later.
www.jeanpaulva.com
108
There are multiple Event Types for a List: List Events List Item Events (Add, Edit, Delete) Web Events Feature Events Workflow Events
www.jeanpaulva.com
109
By default the machine site will be shown in the dialog box. Leave the default option of Sandboxed solution and click the Next button.
www.jeanpaulva.com
110
Select the List Item Events and use the event source as Contacts. Check the check boxes for added, updated and deleted events and click the Finish button. Note: The site URL can be changed later. For the time being we are using hard coded URLs. On clicking the Finish button, the code will be generated for the List Event Receiver and you can place a break point in the ItemAdding event as shown below:
Now execute the application and your Event will be added and activated. Try adding a new contact inside SharePoint:
www.jeanpaulva.com
111
On clicking the Save button, the breakpoint inside Visual Studio will be hit:.
SPItemEventProperties
You can cancel the operation by using the Cancel property. You can report an error message using the ErrorMessage property.
www.jeanpaulva.com
112
Now try Deleting an item without Visual Studio Debugging. You will get the same Error Message Dialog. This concludes the Event Creation and Deployment to a SharePoint site.
Properties of Project
www.jeanpaulva.com
113
You can change the URL and other properties created through the Wizard. Use Project > Properties to access and modify these properties.
Features
The event receiver is actually deployed as a feature inside SharePoint. You can view the Feature properties and the associated XML file under the Features special folder as shown below:
www.jeanpaulva.com
114
The Event code and Elements.xml reside inside the EvntReceiver1 group as shown below:
References
http://msdn.microsoft.com/en-us/library/bb736146(v=office.12).aspx
Summary
In this chapter we have explored the List Event facility of SharePoint. In advanced List Management these flexibilities are a great tool for a SharePoint Developer.
www.jeanpaulva.com
115
Pre-Requisite
For proceeding with that we need to create a List named Tasks using the Tasks template.
Now create a new SharePoint Console Application project inside Visual Studio.
Make sure you changed the Application Target Framework to the .Net 3.5 version.
Adding an Item
To add a new Task Item execute the following code:
using (SPSite site = new SPSite("http://appes-pc"))
www.jeanpaulva.com
116
{ using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["Tasks"]; SPListItem item = list.Items.Add(); item["Title"] = "New Task"; item["Description"] = "Description of Task"; item.Update(); } }
Now you can check the Tasks list inside SharePoint and you will see the new item there.
Editing an Item
For editing an existing Task use the following code. Here we are changing the first item Title and Description.
using (SPSite site = new SPSite("http://appes-pc")) { using (SPWeb web = site.OpenWeb()) { SPList list = web.Lists["Tasks"]; SPListItem item = list.Items[0]; item["Title"] = "Edited Task"; item["Description"] = "Description of Task (edited)"; item.Update(); } }
Going back to SharePoint you will see the Edited Task, as in:
Deleting an Item
For deleting an item use the following code:
using (SPSite site = new SPSite("http://appes-pc")) { using (SPWeb web = site.OpenWeb())
www.jeanpaulva.com
117
Now you can go back to SharePoint and see that the item was deleted.
References
http://suguk.org/blogs/tomp/archive/2006/09/28/Adding_SPListItems.aspx
Summary
In this chapter we have experimented with the List manipulations Add, Edit and Delete through code. In real life we will need to automate List manipulations and programming will be a help in this regard.
www.jeanpaulva.com
118
Enter the name as Coders. Select the site from the wizard as shown below:
www.jeanpaulva.com
119
Enter the details as shown above and click the Finish button to close the wizard. Now the Solution Explorer looks like below:
Open the ListDefinition1>ListInstance1>Elements.xml (Please note that there are 2 Elements.xml inside the Solution Explorer) Change the Title and URL attributes as in the following:
<?xml version="1.0" encoding="utf-8"?>
www.jeanpaulva.com
120
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ListInstance Title="Coders" OnQuickLaunch="TRUE" TemplateType="10000" Url="Lists/Coders" Description="My List Instance"> </ListInstance> </Elements>
Now click the Build button and on success, right-click the Project and click Deploy. If no error messages are there, the Deployment succeeded and you will see the new List inside SharePoint.
On clicking the Coders list you will see the new list opened in SharePoint. Now we need to add a custom column to the List Definition. Our column is of Single line and the name is CoderName. The following are the activities included in the Column Creation. Create a new Field Specify the properties like ID (GUID), Name etc. Add the Field Reference inside Default View
Inside the Fields section of Schema.xml add the following Field definition:
<Field Type="Note" Name="CoderName" DisplayName="CoderName" Required="FALSE" ID="{1D54AAC6-DBB8-4454-91B7-E2FAE7697D6A}"></Field>
www.jeanpaulva.com
121
Inside the ViewFields section of the second View, add the following FieldRef node.
<FieldRef Name="CoderName"></FieldRef>
You can go back to SharePoint and Refresh the Coders List. The changes are visible there, as in:
The new CoderName property is visible now. This concludes our List creation using Visual Studio. For adding more columns, use the Schema.xml file.
References
http://msdn.microsoft.com/en-us/library/ms466023.aspx http://onlinecoder.blogspot.com/2011/03/simple-way-of-creating-sharepoint-2010.html
Summary
In this chapter we have explored the List Definition creation using Visual Studio. The attached source code contains the example we discussed. You can try building and deploying it.
www.jeanpaulva.com
122
Now run the application and you will see the new Document Library created inside SharePoint.
www.jeanpaulva.com
123
Document Templates
The following are the available SharePoint 2010 document templates: Template ID 100 101 103 104 121 122 123 111 102 105 106 1000 Description No Template Word 2003 document Excel 2003 document PowerPoint 2003 document Word document Excel document PowerPoint document OneNote Notebook SharePoint Designer HTML document ASPX Web Page ASPX Web Part Page InfoPath document
Uploading Document
Now we can try uploading a document to the above library programmatically. Use the following code to upload an Excel file. Make sure the application bin folder contains a file named sample.xlsx.
using (SPSite site = new SPSite("http://appes-pc/my/personal/dotnet")) { using (SPWeb web = site.OpenWeb()) { SPDocumentLibrary library = web.Lists["My Docs"] as SPDocumentLibrary; SPFile file = library.RootFolder.Files.Add("sample.xlsx", File.ReadAllBytes("sample.xlsx")); } }
www.jeanpaulva.com
124
Downloading Document
Now we can try downloading a document from the above library programmatically. Use the following code:
using (SPSite site = new SPSite("http://appes-pc/my/personal/dotnet")) { using (SPWeb web = site.OpenWeb()) { SPDocumentLibrary library = web.Lists["My Docs"] as SPDocumentLibrary; SPFile file = web.GetFile(library.RootFolder.Url + "/sample.xlsx"); Stream stream = file.OpenBinaryStream(); FileStream fileStream = new FileStream("out.xlsx", FileMode.OpenOrCreate, FileAccess.Write); int buffer = 4096; int read = buffer; byte[] bytes = new byte[buffer]; while (read == buffer) { read = stream.Read(bytes, 0, buffer); fileStream.Write(bytes, 0, read); if (read < buffer) break; } stream.Dispose(); fileStream.Dispose(); } }
After running the program, you will see that the file is created in the bin folder.
www.jeanpaulva.com
125
This concludes the following activities: 1. Create Document Library 2. Upload a Document 3. Download a Document
References
http://www.learningsharepoint.com/2010/06/30/programatically-creating-document-sets-insharepoint-2010/
Summary
In this chapter we have seen the creation of a document library through code. Please note that, using the Document Type, we can create various types of document libraries.
www.jeanpaulva.com
126
We can create a Web Part in the following ways: 1. Inside SharePoint 2. Using Visual Studio
www.jeanpaulva.com
127
In the next page select the site and click the Finish button. Inside Solution Explorer, open the Visual Web Part User Control. This control represents the User Interface of the Web Part.
www.jeanpaulva.com
128
Building
Now build the project and once it succeeds, use the Deploy option of the project.
Wait for a few minutes and our Web Part is deployed into the SharePoint site.
www.jeanpaulva.com
129
Inside the Custom category we can see the newly created Web Part. Click on the Add button and you will see the Web Part as shown below.
Here the User Control (ASCX) is rendered to the Web Part using the Controls.Add() method. Note: In this example we have just used the label control. We can use the other ASP.NET controls inside Web Parts.
www.jeanpaulva.com
130
Tool Parts
Along with the Web Part, we can associate specific controls in the properties area of the Web Part. The Edit Web part command brings the Tool window to the right side.
If we add a custom control or property into the above area it is called a Tool Part. We are experimenting with adding a Tool part consisting of the following controls: Drop Down List with existing List Names Text Box control to capture the Customer Name
The following are the activities involved: Add a CustomerName property inside Web Part Create a custom class inheriting ToolPart Render Controls inside ToolPart
www.jeanpaulva.com
131
www.jeanpaulva.com
132
panel.Controls.Add(_dropDownList); panel.Controls.Add(textbox); Controls.Add(panel); base.CreateChildControls(); } public override void ApplyChanges() { VisualWebPartProject1.VisualWebPart1.VisualWebPart1 webpart = (VisualWebPartProject1.VisualWebPart1.VisualWebPart1)this.ParentToolPane.SelectedWebPart; webpart.CustomerName = "You selected: " + _dropDownList.SelectedValue; } }
Build and Deploy the project and use the Edit Web Part option. You will see the new controls in the Tool Part panel as shown below:
Select a List item and click the Ok button. You will see the List item name displayed in the Web Part as shown below:
133
The following is an example code for the custom property: Property Browsable DefaultValue WebPartStorage FriendlyName Description Description If false, the property is not displayed on the Web Part property pane Default Value for the property Shared, Personal and None are the enumeration members The name for the property for display purposes The tooltip about the property
References
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpart.aspx http://archive.msdn.microsoft.com/DataAccessWebPart http://www.zimmergren.net/technical/how-to-custom-web-part-properties-toolpart http://msdn.microsoft.com/en-us/library/dd584174(v=office.11).aspx
Summary
In this chapter we have explored Web Parts creation, data access, connectable Web Parts etc. In real-world scenarios Web Parts provide a handy tool for the developer. The attachment contains the source code we discussed.
www.jeanpaulva.com
134
135
Now place a button and image control on the Web Part user control. On the button click event place the following code:
protected void Button1_Click(object sender, EventArgs e)
www.jeanpaulva.com
136
{ Image1.ImageUrl = "/_layouts/images/ImageFileInWebPart/Jellyfish.jpg"; }
Please note that the URL starts with the _layouts folder.
References
http://rtmgroupq8.com/en/add-image-to-sharepoint-visual-web-part http://msdn.microsoft.com/en-us/library/cc768621.aspx
Summary
In this chapter we have explored more features regarding Web Parts. The Images mapping is an essential feature and will take extra time in real-world development scenarios if we do not understand the feature. The attached source code contains the examples we discussed.
www.jeanpaulva.com
137
The connected Web Part resolves the following requirements: Master Web Part and Slave Web Part data exchange Data Selection and Data Display Web Part communication
A Summary of the application is: There are 2 Web Parts Web Part 1 has a drop down list for selecting Car Web Part 2 displays the car picture, based on the selection
Steps Involved
The following are the steps involved in creating connected Web Parts: 1. 2. 3. 4. 5. Create Project Create Communication Interface Create Web Part 1 (Provider) implementing Interface Create Web Part 2 (Consumer) Build and Deploy
Create Project
We can experiment with a Car showcase application where there are 2 Web Parts, as in: The first Web Part allows selecting a Car from the drop down list. The second Web Part displays the image of the car.
For starting with that create a new Web Part project inside Visual Studio.
www.jeanpaulva.com
138
Remove the default VisualWebPart1 Web Part. We will be adding our own Web Parts.
Create Interface
For communication between the 2 Web Parts we need to create an interface. Please create the following interface, which returns the selected Car name:
public interface ICar { string Car { get; } }
www.jeanpaulva.com
139
DropDownList1.Items.Add("Figo"); DropDownList1.Items.Add("Diablo"); } } // Property to expose selected car outside public string Car { get; set; } // Set the Car property protected void Button1_Click(object sender, EventArgs e) { if (DropDownList1.SelectedItem != null) Car = DropDownList1.SelectedItem.Text; } }
Inside the CarSelectionWebPart.cs (Web Part class file) add the following code:
// Property to return the selected Car public string Car { get { return (_control as CarSelectionWebPartUserControl).Car; } } // Special Purpose Attribute to denote ICar interface is provided [ConnectionProvider("Car")] public ICar GetCar() { return this; }
The ConnectionProvider attribute and the interface of the method denotes that this Web Part provides data for an ICar interface. The Connection Provider also says that the name is Car (in string).
www.jeanpaulva.com
140
Image1.ImageUrl = "/_layouts/images/ConnectedWebParts/Camry.png"; else if (car == "Figo") Image1.ImageUrl = "/_layouts/images/ConnectedWebParts/Figo.png"; else if (car == "Diablo") Image1.ImageUrl = "/_layouts/images/ConnectedWebParts/Diablo.png"; }
Now add an Images Mapped Folder and place 3 image files (Camry.png, Figo.png and Diablo.png) inside the folder as shown below:
www.jeanpaulva.com
141
Set Connection
Use the context menu of CarDisplayWebPart to set the connection to provider Web Part.
www.jeanpaulva.com
142
www.jeanpaulva.com
143
References
http://msdn.microsoft.com/en-us/library/ms469765.aspx http://rtmgroupq8.com/en/add-image-to-sharepoint-visual-web-part
Summary
In this chapter we have explored the Connected Web Parts feature of SharePoint Web Parts. In real-world scenarios there could be multiple Web Parts communicating with each other through connected Web Parts. SharePoint also supports AJAX enabled Web Parts which provide a better communication between Web Parts. The attachment contains the source code of the Web Parts we discussed.
www.jeanpaulva.com
144
LINQ to SharePoint is a new feature of SharePoint 2010. LINQ stands for Language Integrated Query which is a part of the .NET Language. The purpose of LINQ is to support various data sources using the same Typed Query Syntax. Presently it supports Objects, Datasets, SQL, Entities, XML etc.
What is SPMetal?
As we will be creating custom lists having custom column names, we need to generate the Entity Model. The SPMetal.exe is the tool which helps in generating the Model classes. Although we can create the Model classes manually, it will be a tedious job and error-prone. Using SPMetal would be the right approach to model classes.
Activities
The following are the activities performed in this chapter: 1. 2. 3. 4. 5. 6. Manager List Creation Entity Creation Read using LINQ Insert Entity Update Entity Delete Entity
www.jeanpaulva.com
145
Now run the following command: SPMetal.exe /web: http://YOURSITE /code: SiteEntities.cs Wait for a while and you will be ready with the new file. Open the file SiteEntities and you will see the Manager class is contained inside.
www.jeanpaulva.com
146
Create Application
Create a new SharePoint > 2010 > Console Application (targeting .Net 3.5 framework) and add the SiteEntities.cs file into it.
You can try with the following operations Read, Insert, Update and Delete using LINQ to SharePoint.
www.jeanpaulva.com
147
Selecting an Item
Now we are trying to select the managers with their country as USA:
using (SiteEntitiesDataContext context = new SiteEntitiesDataContext("http://appes-pc")) { var result = context.Manager.Where(m => m.Country == "USA"); foreach (ManagerItem manager in result) { Console.WriteLine(manager.Name); } }
Note: You can use LINQ or a Lambda Expression to do the query. In the preceding example I used a Lambda Expression. On executing the application you will see the following results:
Inserting an Item
For inserting a new item into the Manager list, use the following code:
using (SiteEntitiesDataContext context = new SiteEntitiesDataContext("http://appes-pc")) { ManagerItem manager = new ManagerItem(); manager.Name = "New Manager"; manager.Address = "New Address";
www.jeanpaulva.com
148
After executing the application, open the Manager list inside SharePoint as shown below:
Updating an Item
For updating an item inside SharePoint use the following code:
using (SiteEntitiesDataContext context = new SiteEntitiesDataContext("http://appes-pc")) { ManagerItem manager = context.Manager.Where(m => string.IsNullOrEmpty(m.Title)).FirstOrDefault(); if (manager != null) manager.Title = "New Title"; context.SubmitChanges(); }
Deleting an Item
For deleting an item inside SharePoint use the following code:
using (SiteEntitiesDataContext context = new SiteEntitiesDataContext("http://appes-pc")) { ManagerItem manager = context.Manager.Where(m => m.Title.Length > 3).FirstOrDefault(); if (manager != null) context.Manager.DeleteOnSubmit(manager); context.SubmitChanges(); }
149
This concludes our Read, Insert, Update and Delete operations using LINQ to SharePoint. I hope the topics are understood by the reader.
References
http://msdn.microsoft.com/en-us/library/ee535491.aspx http://msdn.microsoft.com/en-us/library/ee538255.aspx
Summary
In this chapter we have explored LINQ and the SPMetal tool. This information is necessary in real-world programming scenarios. The attachment contains the source code we discussed.
www.jeanpaulva.com
150
Web Services
SharePoint Web Services is a good feature that allows us to access or change the SharePoint items remotely. We can use Web Services to add more power to our application. The following are the core features of SharePoint Web Services: Foundation and Server Web Services More Interoperability compared with the Server Object Model Above 25 Web Services Manage Sites, Lists, Libraries, and Picture Libraries etc. Run queries against the server Custom Web Service creation possible
The following table contains some of the web services inside SharePoint 2010. Service WebSvcAdmin WebSvcLists WebSvcAlerts WebSvcAuthentication WebSvcsites WebSvcspsearch Description Creation and Deletion of sites List Management service List Item Events service Authentication based service Web sites management service Searching service ASMX Admin.asmx Lists.asmx Alerts.asmx Authentication.asmx Sites.asmx Search.asmx
www.jeanpaulva.com
151
Using http://appes-pc/_vti_bin/Lists.asmx
www.jeanpaulva.com
152
Now we need to add a Web Reference. In Visual Studio 2010 this option is available under the Add Service Reference option as shown below:
www.jeanpaulva.com
153
www.jeanpaulva.com
154
You will get the following dialog. This dialog is suitable for adding web service references.
www.jeanpaulva.com
155
Enter the URL of the Lists.asmx as shown above. You need to replace the PC name with yours. Set a Web reference name in the second highlighted box. This serves as the namespace. Click the Add Reference button and your proxy class and related classes will be ready within a while. Inside the Program.cs enter the namespace and you will see the classes inside it as shown below:
www.jeanpaulva.com
156
Setting Credentials
Whenever we open a SharePoint site (without anonymous login enabled) the site will prompt for user credentials. As we are invoking through a web service the prompt dialog wont be working. We need to pass the credentials using the property named Credentials, as in:
client.Credentials = new NetworkCredential("appes", "password"); / // using System.Net;
Use the following code to fetch the data and display it to the console:
SPReference.Lists client = new SPReference.Lists(); client.Credentials = new NetworkCredential("appes", "PWD"); System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); System.Xml.XmlElement viewFields = xmlDoc.CreateElement("ViewFields"); viewFields.InnerXml = "<FieldRef Name=\"Title\" />" + "<FieldRef Name=\"Name\" />" + "<FieldRef Name=\"Address\" />";
www.jeanpaulva.com
157
XmlNode listItems = client.GetListItems("Manager", null, null, viewFields, null, null, null); foreach (XmlNode node in listItems) if (node.Name == "rs:data") for (int f = 0; f < node.ChildNodes.Count; f++) { if (node.ChildNodes[f].Name == "z:row") { string title = node.ChildNodes[f].Attributes["ows_Title"].Value; string name = node.ChildNodes[f].Attributes["ows_Name"].Value; string address = node.ChildNodes[f].Attributes["ows_Address"].Value; Console.WriteLine(title + " " + name + " " + address); } } Console.ReadKey(false);
The following are the steps involved in getting list item data: 1. 2. 3. 4. 5. 6. Create List Proxy client Set Credentials Set the View Columns Invoke the GetListItems() method Iterate through the nodes Get the value of the node having the name z:row
www.jeanpaulva.com
158
Note
Using web services, XML is used to represent the data. For advanced programming using properties please refer to the Server Object Model and SharePoint LINQ chapters.
References
http://msdn.microsoft.com/en-us/library/ee705814.aspx http://msdn.microsoft.com/en-us/library/ms583494.aspx http://msdn.microsoft.com/en-us/library/lists.lists.getlistitems(v=office.12).aspx
Summary
In this chapter we saw the Web Services feature of SharePoint 2010. It provides the flexibility of interoperability compared with the Server Object Model. Developers can access and manage SharePoint site from non .Net platforms like Java. The attached source code contains the example we discussed.
www.jeanpaulva.com
159
Search
www.jeanpaulva.com
160
Search
In this chapter we can explore one of the core features of SharePoint. It is considered to be the Enterprise feature of SharePoint. SharePoint allows configuration of Search based on various parameters. In short we can configure the breadth and depth of the search.
Search Architecture
Inside SharePoint 2010, Search is a service application. The Search Engine can Index SharePoint Sites, External contents, Files, Web sites etc. The following are the server roles inside the SharePoint Search: 1. 2. 3. 4. Crawler Indexer Query Servers Search Center
Crawlers represent small programs which are scheduled to run on specific intervals. The Crawlers passes through each Content Source and Index the words in one location. These programs will be scanning Documents, Files and other Content Sources. Crawling consists of Full Crawl and Incremental Crawl. We can manually start the crawling process as well as schedule it. The Indexer will create index files which contains the words and corresponding content source information for easier access. The indexing server can be configured to be a separate machine in a farm. As the crawler will be encountering many file types like Word Document, PDF Document, Excel Document, Web sites, Text Files etc. it will be run out of logic on indexing these. We need to specify external Index Filters to tell how to index those file types. These Index Filters are also known as an IFilter. The IFilter reads the contents of the file and creates the index keywords based on the content. Administrators need to configure each file type with an appropriate IFilter. The Query Server is responsible for handling user search queries. In a farm environment, a query server can be configured to be a separate machine. The query server operates on the index files for returning search results. Search Center is a site inside SharePoint 2010 oriented towards Search. It allows configuring of Results, Advanced Search options, Navigation Elements etc. The user can create his own Search Site by using the Basic Search Center template.
www.jeanpaulva.com
161
Now we can try searching some text. Enter the address word of a contact and click the search button.
You will see the following results showing the data from the Manager List and Edit form.
The search result fetched the contents of all list items inside the site. Now we can try searching with keyword Manager. The result will include the Manager list item name too.
www.jeanpaulva.com
162
References
http://technet.microsoft.com/en-us/sharepoint/ee518667 http://technet.microsoft.com/en-us/library/cc263144(office.12).aspx http://msdn.microsoft.com/en-us/library/ms545957(v=office.12).aspx
Summary
In this chapter we have learned the Search feature of SharePoint. Although Search is configured by SharePoint Administrators, still the Developer can use the extended Search web services, Programmatic retrieval of content using Object Model etc.
www.jeanpaulva.com
163
Content Sources
In this chapter we can explore Content Sources and how to add a new Content Source.
Content Sources
Content Source represents the origin of content. As SharePoint handles various contents like Database, File System etc. there should be an Indexing Service to handle all these sources. Please note that SQL Server has a Full Text Search index, but SharePoint has its own Indexing engines. By default SharePoint searches in the site collection and document libraries. Using Custom Content Source configuration we can make SharePoint search the possible areas: File System Drives Network Drives Lotus Notes Data Web Sites
www.jeanpaulva.com
164
Ensure that the above folder contains a text file with data, for example: MyTodo. 2. Open the Central Administration web site and click on the Manage Service Applications link, as in:
www.jeanpaulva.com
165
3. Click on Search Service Application from the page that appears, as in:
www.jeanpaulva.com
166
5. Click on the New Content Source link from the page that appears, as in:
www.jeanpaulva.com
167
Click the OK button and the Crawler will perform a crawl. 7. Go back to the main site and enter the keyword to search for (MyToDo). You can view the following results:
www.jeanpaulva.com
168
This concludes our chapter on adding Content Source and doing a sample search.
www.jeanpaulva.com
169
Starting Crawls
We can start / stop / pause crawls manually by using the command bar as shown below. Please note that only after a full crawl the data will be searchable.
Summary
In this chapter we have explored how to add a content source inside a SharePoint site.
www.jeanpaulva.com
170
www.jeanpaulva.com
171
2. Click on the Scopes link as highlighted above; you will then get:
3. Click on the New Scope link from the page that appears. Enter the details as shown below and click the OK button.
4. Click the Add rules for our newly created scope as shown below:
5. Set the properties as shown below (Pointing to our File System Content Source):
www.jeanpaulva.com
172
Click the OK button to continue. Now we are ready with a Scope set with rules. But in order to view the scope in the Search drop down list, we need to do the following steps. 6. Click Search Administration > Start Updating Now link as shown below:
7. Now open our default SharePoint site and open the Site Settings > Search scopes.
www.jeanpaulva.com
173
8. Click the Display Groups button from the top bar as shown below:
10. Select the File System Scope and click the OK button; see:
www.jeanpaulva.com
174
Now the Search Scope is ready within our site. You can experiment with it by opening a site and selecting the scope from the scope drop down list.
References
http://office.microsoft.com/en-us/sharepoint-server-help/managing-search-scopes-HA001160438.aspx
Summary
In this chapter we experimented with the manage search scope feature of SharePoint. In a real-world scenario Administrators need to configure various search scopes for different site collections.
www.jeanpaulva.com
175
www.jeanpaulva.com
176
www.jeanpaulva.com
177
5. Click on the Local SharePoint sites cell and in the page on the right side you will see the Crawl Schedules.
www.jeanpaulva.com
178
You will see two items: Full Crawl and Incremental Crawl.
Full Crawl
To start with we have to use Full Crawl. This will be time-consuming and provides the starting point for Incremental Crawls. A Full Crawl replaces all existing crawl contents regardless of whether they have changed or not.
Incremental Crawl
These are faster crawls as they crawl only modified crawls. A Full Crawl has to be performed previously to do the Incremental Crawl. 6. Use the Create Schedule link to create a new Crawl Schedule, as in:
www.jeanpaulva.com
179
7. Enter the details in the dialog that appears and click the OK button; see:
www.jeanpaulva.com
180
You will see that the site is reflected with the new crawl schedule:
References
http://social.technet.microsoft.com/wiki/contents/chapters/full-and-incremental-crawls-in-microsoftoffice-sharepoint-server-2007-search.aspx
Summary
In this chapter we saw how to create a crawl schedule.
www.jeanpaulva.com
181
Search Alerts
In this chapter we can examine the Search Alerts feature of SharePoint.
2. Now click on the Email button which is highlighted above. You will get the following screen:
www.jeanpaulva.com
182
Enter the details and click the OK button. Your Search Alert is ready. For testing the alert, create a list content with the Alert Keyword. You will get email notification for it as a daily or weekly summary based on the option you have selected. We can also add RSS feeds as an alternative for Email.
References
http://www.bainsight.com/blog-archive/Pages/5-12-2011.aspx
Summary
In this chapter we have explored the Search Alerts feature of SharePoint.
www.jeanpaulva.com
183
BCS
www.jeanpaulva.com
184
BCS Architecture
The BDC Runtime is responsible for connecting to the external data sources. External data sources connections are stored in BCS Metadata inside SharePoint. The BCS Metadata allows connecting to the data sources in offline mode too. SharePoint acts as a Presentation layer in this scenario.
Note
The previous version of BCS was BDC (Business Data Catalog). Following are the components of BCS.
www.jeanpaulva.com
185
SharePoint Designer
We can use the SharePoint Designer provided tools for creating BCS Solutions.
References
http://msdn.microsoft.com/en-us/magazine/ee819133.aspx http://msdn.microsoft.com/en-us/library/ie/ee557898.aspx
Summary
In this chapter we have explored the BCS feature of SharePoint 2010. In the next chapter we can experiment with creating a BCS external content type inside SharePoint.
www.jeanpaulva.com
186
The following are the activities involved: 1. 2. 3. 4. 5. Create database and table Using SharePoint Designer create BCS External Content Type Using SharePoint Designer create Add/Edit/Delete operations metadata Using SharePoint Designer create Lists & Form Using Central Administration set Permissions for external Content Type
1. Create database and table Create a database and table named Customer with the following fields:
2. Using SharePoint Designer create BCS External Content Type Now we can create an External Content type using SharePoint Designer. Start the Designer application and open our SharePoint web site > External Content Types as shown below.
www.jeanpaulva.com
187
Click on the External Content Type button from the top side. In the window that appears change the Name and Display Name (click on the links) as shown below.
www.jeanpaulva.com
188
Now click on the External System link and you will get the following dialog:
www.jeanpaulva.com
189
Click on the Add Connection button and select SQL Server in the dialog that appears; see:
www.jeanpaulva.com
190
Click the OK button and your server connection is ready. 3. Using SharePoint Designer create Add/Edit/Delete operations metadata From the appearing tables list select the Customer table and right-click to get the context menu. Use the Create All Operations menu item to get the Add/Edit/Delete operations wizard.
www.jeanpaulva.com
191
4. Using the SharePoint Designer create Lists & Form Now the operations are ready and we need to create the List Form and the associated Add/Edit/Delete forms inside SharePoint.
www.jeanpaulva.com
192
From the toolbar, click on the Create Lists & Form button as highlighted above. In the dialog box enter the name for the List and click the OK button as shown below.
5. Using Central Administration set Permissions for external Content Type Now you can try viewing the Customer Data list inside SharePoint.
www.jeanpaulva.com
193
On clicking the list, you will be seeing an Access Denied by Business Data Connectivity error message. To resolve this we need to set permission for the External Content Type. Open the SharePoint Central Administration website. Click on Manage Service Applications.
In the page that appears click on the Business Data Connectivity Services link as shown below:
www.jeanpaulva.com
194
In the list, hover over the Customer Data item and click on the Set Permissions menu item as shown below.
www.jeanpaulva.com
195
Enter the user name, click the Add button and check all permissions. Click the OK button to close the wizard. (Make sure you are adding the username used to view SharePoint.) Now you are ready with the Permissions. Go back to the SharePoint > Customer Data list and you will be able to see the data as shown below.
Now you can play with the View/Edit/Delete features of the BCS list.
References
http://www.zimmergren.net/technical/access-denied-by-business-data-connectivity-solution
Summary
In this chapter we saw how to create an External Content Type through Business Connectivity Services and view it inside SharePoint. In a real-world scenario using BCS we can connect to WCF Services and other Business Applications like Microsoft CRM to view and update data inside SharePoint.
www.jeanpaulva.com
196
Workflows
www.jeanpaulva.com
197
Workflows
In this chapter we can explore the Workflow feature of SharePoint 2010. It adds much power and flexibility to SharePoint and is a must have skill for advanced SharePoint users or administrators.
What is Workflow?
Workflow started as a component of the .Net Framework 3.0 named Windows Workflow Foundation. Workflow represents a sequence of activities as in a Flow Chart and a runtime that executes these activities. The Workflow activities are executed inside a: Windows Application SharePoint Server ASP.NET Application
Workflow is integrated in SharePoint 2010. We can create Workflows using SharePoint Designer, Visio and Visual Studio.
Scenario to reveal the advantage of Workflow: Create a Task List of Id, Name, and Status. When Status is Completed, Move the item to Completed Task List Using ASP.NET Using SharePoint and Workflow Time Required
8 Hours 5 Minutes
www.jeanpaulva.com
198
From the above scenario we can understand the cost and time saviings using Workflows. It allows dragging and dropping the common programming scenarios. We can also do advanced activities by programming extensions of Workflows.
www.jeanpaulva.com
199
There is a similar term called Globally Reusable Workflow which requires conversion of existing Reusable Workflow. Once it is converted the Workflow can be used with the whole site collection. We can export the workflow as a template to be used with another site collection. We can also import the WSP (Windows SharePoint Solution) file inside Visual Studio using the Import Reusable Workflow wizard.
In the case of a manual start, the user or administrator must click some buttons for the workflow to start. In the case of automatic start the workflow executes automatically. This can be configured along with a list or library like: Creation of an Item begins An Update of an Item begins etc.
References
www.jeanpaulva.com
200
Summary
In this chapter we have explored the Workflow feature of SharePoint 2010. In the next chapter we can experiment with creating workflows.
www.jeanpaulva.com
201
A List Workflow can be associated with a list. A Reusable Workflow can be associated in more general ways like a Content Type. A Site Workflow is associated with site items.
Builtin Workflow
Inside the Designer we can see the Globally Reusable Workflows which can be globally used in the site collection. We can copy and modify them instead of modifying them directly.
Creating a Workflow
www.jeanpaulva.com
202
Now we can experiment with creating a Workflow using SharePoint Designer. The following are the steps involved. Step 1: Create Team Site Open the SharePoint Designer from the Start menu. Click on the Team Site button and enter the name of the new web site (mynewsite) as shown below.
This step will create a new site with a Tasks list. Step 2: Create Workflow Select the Workflows item from the left side Navigation pane.
www.jeanpaulva.com
203
Click on the List Workflow button from the ribbon and click the Tasks item.
In the dialog that appears enter the name of the new Workflow as shown below.
www.jeanpaulva.com
204
Step 3: Create Condition and Action Now we need to specify the Condition and Action of the item. Each Condition will have one or more Action items associated with it. The Condition will be evaluated and the corresponding Actions will be executed. The Condition could be like checking a field property of the list or library, checking the user name etc. The Action is the actual performing item. The Action could be like updating a field of the current item, moving the list item to another list, emailing a user, adding a comment, checking out a document, invoking another workflow etc. You can create Condition and Action using the ribbon items.
www.jeanpaulva.com
205
For creating the condition, use the Insert > Condition > If current item field equals value. Your Workflow will look like below. The links field and value has to be specified.
Click on the links above and set the links as shown below:
www.jeanpaulva.com
206
Now click the Insert > Actions > Set field in current item. Modify the comment as Good Job Dude! as shown below.
Click on the Save button and we are ready with the Condition and Action. The condition and Action checks the item of the Task and if the Status is Completed the Description column is set to a message. Step 4: Change Workflow Settings Go to the Navigation > Workflows list and use the Workflow Settings menu item.
www.jeanpaulva.com
207
In the Start Options section on the right do the following: 1. Uncheck the Allow this workflow to be manually started item 2. Check the other two items for ensuring automatic execution of the Workflow This ensures that our workflow will be automatically executed on an insert or update of the Task item in the Task List. Click on the Save button and after that click on the Publish button.
Now our workflow is ready and deployed to the SharePoint site named mynewsite. Step 4: Test the Workflow We can test the workflow by opening the above site in a browser.
www.jeanpaulva.com
208
Click on the Tasks list and create a new item. Set the Status of the Task to completed. Leave the Description field as empty as shown below. Click on the Save button.
You will see that a new column for the Workflow appeared for the above task item. Workflows will add their own columns to the context list. Refresh the page and wait until the Workflow status is Completed.
Now try viewing the item again and you will see that the Description has changed to our message.
www.jeanpaulva.com
209
References
http://blog.sharepointelearning.com/workflow-designer-in-sharepoint-designer-2010/
Summary
In this chapter we have experimented with creating a workflow with SharePoint Designer 2010. In the upcoming chapter we can create a workflow using Visual Studio.
www.jeanpaulva.com
210
Types of Workflows
There are basically 2 types of workflows inside Visual Studio: Sequential Workflow State Machine Workflow
A Sequential Workflow, once invoked, continues executing until it is completed. A State Machine Workflow will be have persisted states. The states could continue execution between machine restarts. In this example we are trying to create a Workflow which, on activation, updates the null Address column of the Manager list. (You need to have a Contact template named Manager.) Step 1: Create Sequential Workflow Project For the time being we can start with a Sequential Workflow. Start Visual Studio and create a new project from the template SharePoint > Sequential Workflow.
www.jeanpaulva.com
211
In the Next screen select the option Site Workflow as shown below:
In the next screen leave the default option saying the user manually starts the Workflow. Click the Finish button to create the project.
www.jeanpaulva.com
212
You will get the following screen once the project is created.
What is an Activity?
A Workflow consists of a series of Activities. We can add Activities using the Toolbox. There are various types of Activities like Code Activity, SendEmail etc. For our example we are using the more functional Code Activity.
www.jeanpaulva.com
213
Drag and Drop a Code Activity from the toolbox. You can locate this from the v3.0 group inside Toolbox.
Step 3: Add code for the Activity Now we need to add code for this Activity. Double-click on the codeActivity1 item shown above. Place the following code in the code view.
www.jeanpaulva.com
214
private void codeActivity1_ExecuteCode(object sender, EventArgs e) { using (SPWeb web = SPContext.Current.Web) { SPList list = web.Lists["Manager"]; foreach (SPListItem item in list.Items) { if (item["Address"] == null) { item["Address"] = "PLEASE SET THE ADDRESS!"; item.Update(); } } } }
Step 4: Build and Deploy the Solution Now we are ready to build and deploy the solution. Right-click on the solution and use the Build and Deploy commands.
Step 5: Execute the Workflow inside SharePoint Now we are ready to test the Workflow inside SharePoint. Since the Workflow was created as a Site Workflow it will be accessible for all the Lists and Libraries. You can click the Lists link inside the site.
Now click on the Site Workflows link. You will get the following screen:
www.jeanpaulva.com
215
Before executing the Workflow you need to create a Manager item with Address not assigned. Click on the highlighted button and your workflow is executed. Wait for a while and you will see the invalid manager record is updated with the message.
Note
For debugging the Workflow, you can set a breakpoint and use the Debug command of Visual Studio. When the Workflow is executed the breakpoint will be hit.
References
http://www.bing.com/videos/watch/video/getting-started-sharepoint-2010-creating-workflows-withvisual-studio-2010/10tvrof3l
Summary
In this chapter we have experimented with creating a Workflow using Microsoft Visual Studio 2010. In a real-world scenario Workflow Programming helps us in doing complex tasks to include in SharePoint.
www.jeanpaulva.com
216
WSP Extension
A file with a WSP extension represents a SharePoint Solution Package. It is actually a cab file. When we create a workflow and make a WSP file we can use the file to deploy the Workflow to multiple SharePoint sites.
You can get the WSP file inside the bin\Debug folder of the solution.
The WSP file is actually a cabinet file. You can try opening it with Winzip/Winrar as shown below to see the contents.
www.jeanpaulva.com
217
In the dialog box select the WSP file we generated and click the OK button. After this step we need to activate the solution from Site Settings > Galleries > Solutions.
www.jeanpaulva.com
218
After doing the above command open SharePoint Central Administration and from System Settings > Manage Farm Solutions > Select the workflow and click on the Deploy Solution button as shown below.
www.jeanpaulva.com
219
Now go back to the SharePoint site and use Site Actions > Site Settings > Site collection features to activate the workflow.
Now use the Site Actions > Site Settings > Workflow settings page to add the workflow.
The deployment is completed and the Workflow is activated. You can access the workflow from List > Site Workflows > WF2.
www.jeanpaulva.com
220
Click on an existing Workflow, for example Contact Workflow in the above screen. The browser will prompt with a Save As dialog. Click the Save button to get the WSP file. This file can be used to deploy the solution to another SharePoint server.
References
http://technet.microsoft.com/en-us/library/ff608051.aspx http://msdn.microsoft.com/en-us/library/aa543214.aspx http://technet.microsoft.com/en-us/library/cc261956(office.12).aspx
Summary
In this chapter we have experimented with deployment of Workflow using the WSP file.
www.jeanpaulva.com
221
Business Intelligence
www.jeanpaulva.com
222
Introduction
In this chapter we can explore the Business Intelligence feature of SharePoint 2010.
Excel Services
This service provides sharing of Excel work books among users. This service has the capability to render Excel sheets inside a browser. Users can view and edit the Excel sheet using their browsers. This service was introduced in the SharePoint 2007 version. For trying this feature create a Document library template with the Advanced Options set as shown below.
www.jeanpaulva.com
223
Now you can add an Excel sheet inside the library and use the Document > Edit context menu to start editing. This feature requires MS Excel 2010 to be installed in the same machine.
References
http://technet.microsoft.com/en-us/sharepoint/ee692578
www.jeanpaulva.com
224
Summary
In this chapter we have explored the Business Intelligence features of SharePoint 2010.
www.jeanpaulva.com
225
Maintenance
www.jeanpaulva.com
226
The following are the most common administrative tasks: Backup and Restore Site Usage Analysis Cleaning up Unused Sites Managing the Search Service Managing Quotas and Locks
www.jeanpaulva.com
227
Backup
We can perform various levels of backup in SharePoint 2010. The levels include: Farm Backup Site Collection Backup Site Backup Web Application Backup List Backup Library Backup Solution Package Backup Configuration Backup Content Database Backup
The types of Backup are: 1. Full Backup 2. Differential Backup 3. Incremental Backup We can have automated backup strategies to back up the required contents on intervals. The Backup and Restore settings can be accessed from SharePoint Central Administration.
For performing a manual backup use the Perform a backup link shown above. In the page that appears select the items you need to backup and click the Next button. Depending on the item the backup size will increase.
www.jeanpaulva.com
228
In the next page of the backup wizard, enter the backup type and location as shown below.
www.jeanpaulva.com
229
Click the Start Backup button to perform the backup. Make sure you set a location with shared access to everyone.
The above screen shows that your backup operation is running. Wait for a while to complete the operation. After the operation completes you will get the report as shown below.
Note
If the Backup page says the Administrative service is not running, you need to start it manually from the Windows Services. Use the run window to execute the command services.msc. In the applet right-click and start the SharePoint 2010 Administration service.
www.jeanpaulva.com
230
Restore
We can restore a farm, site or the backed up item using the Restore from a backup option.
In the page that appears select the radio button of the appropriate backup and click Next button.
You will see that the backup location is remembered automatically. In real-world scenarios we have to choose a different backup location. In the next page select the components to restore.
www.jeanpaulva.com
231
References
http://technet.microsoft.com/en-us/library/cc261687.aspx
Summary
In this chapter we have explored the common administrative tasks inside SharePoint. Please note that the Backup and Restore operation can be performed programmatically too.
www.jeanpaulva.com
232
Configure Email
In this chapter we can see how to configure the email settings. The email settings are important for the upcoming chapters. The SharePoint automatic schedulers and workflows use the email settings for notification on: Size Quota limit reached Site Inactivity Time exceeded Other Issues Workflow related Mailing
etc.
Central Administration
We need to use the SharePoint Central Administration website to configure email settings. Please make sure that the user is a member of a Farm Administrators group. Open the System Settings link from the left navigation pane as shown below.
We can do the following Email Configurations there: 1. Outgoing Email 2. Incoming Email 3. Mobile Account We will start configuring the outgoing email settings. Click on the Configure outgoing e-mail settings link to get the following page.
www.jeanpaulva.com
233
Enter the email details and click the OK button. Your settings will be changed. These settings will be used by SharePoint server.
References
http://technet.microsoft.com/en-us/library/cc263462.aspx
Summary
In this chapter we have explored the Site Usage Analysis Administration task inside SharePoint 2010.
www.jeanpaulva.com
234
Quotas
Inside SharePoint 2010, the administrator can control the storage limits of users. A Quota specifies the maximum amount of data that can be stored inside a site collection. We can also make a Quota Template that can be used across other sites. The Quota Settings allows Email Notifications in case the quota limit exceeded a particular level. Please follow the steps mentioned to change the Quota Settings. Open the Central Administration website and navigate to Application Settings > Site Collections > Specify Quota Templates.
In the page that appears as shown below you can edit the maximum size for the Personal Site template. You may wish to create a separate template as well.
www.jeanpaulva.com
235
The Quota Settings is set to send Email Notifications when the warning limit is exceeded. The above settings are for the Quota Template. Any change in the template will affect all the sites using this template. If you wanted to change only a particular site collection Quota without changing the Quota template use the following steps. Click on the Application Settings > Site Collections > Configure Quotas and Locks link as shown below.
www.jeanpaulva.com
236
In the page that appears you can set the Quota check box. By default it is unchecked.
www.jeanpaulva.com
237
Locks
Locks allow the administrator to disallow users from viewing, adding, editing, and deleting contents in a site collection. This option could be useful while migrating or doing a backup or restore activity. For performing this action the user should be in the Administrators group. The following are the locking options available in SharePoint 2010. Not Locked: This is the default where users can view and edit site contents Adding Content Prevented: Adding new contents are blocked but edit and delete are allowed Read Only: Users can only view the contents. Add, Edit, and Delete are not allowed No Access: Users are not allowed to access the site For locking a particular site, use the following steps. From the Central Administration web site open the Application Management > Site Collections > Configure quotas and locks option.
In the page that appears as shown below, change the Lock status as shown below.
www.jeanpaulva.com
238
Click the OK button to save the changes. Now you can try accessing your SharePoint default web site. You will get the following error message.
After testing please ensure you change the lock status back to Not locked.
References
http://technet.microsoft.com/en-us/library/cc263480.aspx http://technet.microsoft.com/en-us/library/cc263238.aspx
Summary
In this chapter we have explored the Quotas and Locks feature of SharePoint Administration.
www.jeanpaulva.com
239
The highlighted links allows us to view the Web Analytics reports for Site and Site Collection respectively. For the time being click on the first link and you will get the page below displaying site usage statistics.
www.jeanpaulva.com
240
You can access the following information from this page: 1. 2. 3. 4. 5. 6. 7. Number of Page Views Number of Daily Unique Visitors Number of Referrers Top Pages Top Visitors Top Destinations Top Browsers
We can use the Web Analytics Workflow to send periodic reports about site usage statistics.
www.jeanpaulva.com
241
On clicking the highlighted link as shown above you will get the following page.
Check the email notifications and delete options. You need to configure the outgoing email server to get the options enabled. Click the OK button after the change.
References
www.jeanpaulva.com
242
http://technet.microsoft.com/en-us/library/gg266383.aspx http://technet.microsoft.com/en-us/library/cc262420.aspx
Summary
In this chapter we have explored the Site Usage Analysis Administration task inside SharePoint 2010.
www.jeanpaulva.com
243
In the page that appears click on the Search Service Application row to make it selected and click the Manage button from the ribbon.
www.jeanpaulva.com
244
In the page that appears you will see the various search settings. You can change the associated email address, search user account etc. using the corresponding links.
www.jeanpaulva.com
245
In the page that appears you can set the Proxy server. This is usually needed when crawling internet content.
www.jeanpaulva.com
246
In the page that appears use the New Content Source to add the new item.
Adding a content source was demonstrated in the previous chapter related to Search.
References
http://technet.microsoft.com/en-us/library/ee792870.aspx http://blogs.msdn.com/b/russmax/archive/2009/10/20/sharepoint-2010-configuring-search-serviceapplication-using-powershell.aspx
Summary
In this chapter we have explored the Managing of Search Service inside SharePoint 2010. In a real-world scenario the Search Service application is configured using PowerShell.
www.jeanpaulva.com
247
Windows PowerShell
In this chapter we can explore the Windows PowerShell usage along with SharePoint 2010.
www.jeanpaulva.com
248
Command 1: Get Command List For getting a list of commands in the loaded cmdlet use Get-Command
www.jeanpaulva.com
249
Note
You can also add the MSDOS commands like MORE, CLS and keyboard commands like Ctrl+C, Tab for auto completion etc. For example: Get-Command | MORE (to view page wise) Command 2: Getting Help on a Command For getting help, use the command Get-Help CommandName
www.jeanpaulva.com
250
Command 3: Adding SharePoint Solution to a site Now we can try adding a solution file (WSP) into the SharePoint site. The command is: Add-SPSolution filename
www.jeanpaulva.com
251
Command 4: Remove SharePoint Solution from a site For removing a solution from the site use the following command. The command is: Remove-SPSolution Identity identityname
More Commands
There are more commands in the SharePoint PowerShell cmdlet that perform activities like: Adding / Editing / Removing Content Adding / Editing / Removing Item Change Metadata of Items Install / Uninstall WebPart Install / Uninstall InfoPath Forms Configure Search Service Content Deployment Configure SharePoint Designer Backup / Restore Start / Stop Services
References
http://technet.microsoft.com/en-us/library/bb978526.aspx http://msdn.microsoft.com/en-us/library/ms714469(VS.85).aspx
www.jeanpaulva.com
252
Summary
In this chapter we have explored the Windows PowerShell usage along with SharePoint 2010. The flexibility of automating repeated tasks is achieved using PowerShell and no wonder that it is a power tool in the hands of SharePoint Administrators.
www.jeanpaulva.com
253
Conclusion
I hope information provided in this book was useful. I will be updating this information in the future, so please visit back the website to get the updated ebook. I would like to know the feedback on the technical content and writing style so that I can improve in my further books. You can contact me over: [email protected] [email protected] http://twitter.com/#!/jeanpaulva1 http://jeanpaulva.com/
www.jeanpaulva.com
254