SharePoint 2010 General Lab for Developers (Part 5/5)



Starter files and solutions files can be found here.

In his exercise we will create a web part that retrieves the prerequisite courses of a specific course.

The course code will be a property exposed in a custom toolpart.

Add the following folders (Controls and Webparts) in the CourseSitefeatures project:


In this folder, add a SharePoint project item from the WebPart template and name the class CoursePrerequisites.

Open the generated elements.xml file and set the Group Value to Course Site web parts:


Make sure you understand the details of this elements.xml file: a file coursePrerequisites.webpart will be loaded into the web part catalog list, which is located in _catalogs/wp and of based on the list template 113.

Open the web part file and modify the Title and Description properties and add a new property CatalogIconImageUrl as following:


Add a new feature named CourseSiteWebParts, set the scope to Site; Hidden must be true, and make it dependent on CourseSiteFeature. Add the CoursePrerequisites SharePoint project item into this feature.

Go to your site collection root site, select Site Settings-Galleries-Web Parts and you will find the coursePrerequisites.webpart file. Edit this file and you will see the following properties values :


Add the web part into a web part page to make sure everything is ok (you will notice the picture we specified in the .webpart file):


Add the CourseCode property :


Set the ToolboxItemAttribute to true.

Deploy the project, add the web part to a page and make sure the Course Code property shows up in the web part property page.

We are now going to use an editor part.

Add the CourseEditorParts.cs file from the (starter files) into the CoursePrerequisites item as following:


Analyze the editor part code.

We will now associate the editor part with the Web part : in the web part class, override the CreateEditorParts function:


Since we don’t want to use the default property layout, set the WebBrowsable attribute of the CourseCode property to false :


Deploy your web part and check the web part property page


The web part will now display the prerequisite information by invoking a web service which is provided in your starter files. Create an IIS web site (with the IIS administration console) that points to your web service folder; the web site description can be “Course Web Services”. In the IIS console, authorize any users by clicking on the web site Edit permissions settings (in the Actions panel):


Add Authenticated Users (don’t do this in production!):


Make sure your web service is correctly configured by invoking it from the browser:


Click on the GetPrerequisites hyperlink and type GSP10-6 in the parameter text box :


You should get the following answer:


In your project, add a Service Reference to this web service .

When the following window shows up, click on Advanced :


And click on add Web reference, and name the web reference litware.

Add an SPGridView member to your web part class


Replace the existing CreateChildcontrol() implementation with the one provided in your starter files (snippet1.txt); add also the SelectedIndexChanged(…) function.

Test your work by setting GSP10-6 in the course code property (in the web part property page) :


Your web part should look like this:


Make sure you are jumping to the corresponding site when you click on Jump to Site.

Now we want this web part to be automatically visible in the page describing the course when we create a dedicated course site :


Go to the createcoursite.aspx codebehind and add the following code:


Deploy your project, create a new course site and check the Description tab.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s