You are on page 1of 107

A SharePoint Solutions White Paper

Hands-on with
SharePoint 2010:
Deep Diving With the Experts

750 Old Hickory Blvd, Suite 1-110 November 3, 2009


Brentwood, TN 37027
(615) 515-0210
www.SharePointSolutions.com
Contents

Introduction .................................................................................................................................... 3

Meet the Authors ........................................................................................................................... 3

Ricky Spears................................................................................................................................. 3
Eric Eaton .................................................................................................................................... 3
David Fisher ................................................................................................................................. 4
Jeremy Luerkens ......................................................................................................................... 4
Tony Bierman .............................................................................................................................. 4
What’s New in SharePoint 2010 Lists? (Audience: All) ............................................................. 5

The New Approval Actions in SharePoint Designer 2010 Workflows (Audience: All) ........... 9

The New Chart Web Part in SharePoint 2010 (Audience: All) ................................................. 19

Creating SharePoint 2010 Workflows in Visio 2010 (Audience: All) ...................................... 29

2
SharePoint 2010 * Windows PowerShell = Disaster Recovery (Audience: IT Admins) ...... 38

SharePoint 2010’s New Granular Content Restore Capability (Audience: IT Admins) ........ 49

SharePoint 2010’s New Configuration Restore Capability (Audience: IT Admins) .............. 56

Creating a Custom Ribbon Tab in SharePoint 2010 (Audience: .NET Developers) .............. 63

Create a Custom SharePoint 2010 Picker (Audience: .NET Developers) .............................. 69

Building a SharePoint 2010 Service Application (Audience: .NET Developers) ................... 77

Part One - The Service Application ........................................................................................... 79


Part Two – the Service Application’s Admin Interface.............................................................. 90
Part Three – The WCF Service Endpoint ................................................................................. 100
Part Four – The User Application Page ................................................................................... 102
Introduction
SharePoint Solutions is fortunate to have a broad array of extremely talented SharePoint
experts. Over the years we have assembled a team that includes some of the most respected
SharePoint Architects, Developers, Infrastructure Specialists, Trainers and Consultants in the
business.

This white paper is a compilation of SharePoint 2010 articles that have been written by our
experts as they have dived deep into the feature-set of the new version of SharePoint. As one
of Microsoft’s leading SharePoint partners, SharePoint Solutions has had access to early bits of
SharePoint 2010 and all of these articles were written based on the Technical Preview version
which was released to selected Microsoft partners in July 2009.

We believe that this set of articles is unique in that SharePoint Solutions is the only company to-
date to document in detail, and based on extensive hands-on work, some of the important new
SharePoint 2010 features prior to the release of the public beta in November 2009.

Meet the Authors

Ricky Spears
Managing Director, Training Division and Senior Instructor/Author

Ricky has overall responsibility for the Training Division at SharePoint


Solutions including overseeing course development and instruction. He
has personally authored three advanced courses on WSS 3.0 and
SharePoint 2007 and has provided expert SharePoint consulting services to
clients such as Solo Cup, ConocoPhillips, Turner Broadcasting and many
others.

Eric Eaton
Senior SharePoint Infrastructure Engineer, Instructor, Consultant

Eric specializes in SharePoint Server farm infrastructure. He teaches and


consults frequently on SharePoint Farm architecture and server
administration topics. Prior to joining SharePoint Solutions he was a
SharePoint Server Farm administrator at a large national organization.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 3


David Fisher
SharePoint Software Engineer

David is a .NET developer and builds and supports commercial software


products for SharePoint Solutions. He is currently responsible for the
development of the Workflow Essentials line of SharePoint add-ons.

Jeremy Luerkens
Software Production Manager and Senior Engineer

Jeremy is a .NET developer and manages software production at


SharePoint Solutions. He is the primary architect, designer and developer
of the award-winning Extranet Collaboration Manager for SharePoint 2007
product.

Tony Bierman
Managing Director, Commercial Software Division

Tony is a .NET developer and manages the Commercial Software Division


of SharePoint Solutions. He has been a SharePoint MVP and is widely
recognized as one of the industry’s thought leaders on advanced
SharePoint development topics.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 4


What’s New in SharePoint 2010 Lists? (Audience: All)
By Ricky Spears

In my opinion, lists and libraries are the heart and soul of SharePoint. When I first installed the
Microsoft SharePoint 2010 Technical Preview, the first thing I did was create a new list just to
see what the most obvious changes were. Note: This article and all screenshots are from the
Technical Preview and things may change before SharePoint 2010 is released to the public.

I use custom lists for lots of things, so I started by creating a new custom list. The creation
process wasn’t very different from the process in SharePoint 2007.

The List Ribbon:

Very quickly I noticed that the familiar toolbar at the top of the list had been replaced by a
ribbon, similar to the one in the Office 2007 applications.

The default view of the ribbon after creating a list is the List ribbon. Although I’m used to using
the menus, the ribbon allowed me to more quickly create views, create columns, change list
permissions, go to list settings, and much more.

The New Item Form and the Edit Ribbon

To add a new item to the list, I switched to the Items ribbon and clicked the New Item button.
Instead of switching to a new page to add my new item, a new form appeared in front of my list
and it appeared the lights were dimmed on SharePoint and new form had a spotlight on it. The
new item form had a ribbon itself with quick access to Cut, Copy, and Paste commands, a button
to attach a file, a spell check button, as well as the expected Save and Cancel buttons.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 5


The Items Ribbon

When I checked the box beside one of the items I added in my list, I saw options to work with
that item in the Items Ribbon. From here I could view the item, edit it, delete it, and change its
permissions. I could have done more if my simple custom list had more functionality.

Allow Duplicate Values?

One of the things that has always frustrated me is that I haven’t had a good way to keep people
from entering the same item multiple times in a list. In the Additional Settings section for the
Single line of text, Number, Currency, Date and Time, Lookup, Person or Group, Business data,
and Managed Metadata there is a setting for Allow Duplicate Values.

If you select to not allow duplicate values for a particular column, and you try to add a new item
with an existing value in that column, you will receive an error and have to fix the error to
proceed.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 6


Column Validation

In the past, we didn’t have any way to validate a user’s input in lists and libraries. When you add
new columns of type Single line of text, Choice, Number, Currency, or Date and Time you will
see a section called Column Validation. Here you can enter Excel type formulas that must
evaluate to True before the user can add the item to the list.

If the user’s input doesn’t validate according to your formula, the User Message you entered will
be displayed to the user.

There are also validation settings on the list itself that work similar to the validation settings on
the columns.

Metadata Navigation

In SharePoint 2010 we’ll be able to better locate our data based on its metadata. This can be
configured separately on each list and is a whole other blog post in itself. I thought you might
want to see a screenshot of the settings though, so here you go!

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 7


Form Settings

In the past, if you wanted to change the way a form looked in SharePoint for entering new
information or editing information, you had to create a whole new form using SharePoint
Designer. Now, all those forms are InfoPath forms and selecting the option to edit the form
opens it in InfoPath where you can make any changes you want, then just republish the form.

Conclusion

I’m sure that as we all dig deeper SharePoint 2010 we’ll find even more goodness there, but
these were the first things that caught my eye and I wanted to share these with you. I think
these are all significant advances over lists in SharePoint 2007.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 8


The New Approval Actions in SharePoint Designer 2010 Workflows
(Audience: All)
By Ricky Spears

SharePoint 2007 came with 23 out-of-the-box actions to fit many of the most common tasks
needed in workflows. SharePoint 2010 comes with 44 out-of-the-box actions. All the original
actions are still there, but you now have 21 more! Note: This article and all screenshots are from
the Technical Preview and things may change before SharePoint 2010 is released to the public.

In SharePoint 2007, if you wanted to get approval from a user for something, you usually had to
use the Collect Data from a User action, store a reference to the task ID for the task that was
created, and then lookup the user’s input later in your workflow as needed. Microsoft has
streamlined this process in SharePoint Designer 2010 with the actions for Assign Item for
Approval, Assign Item for Feedback, and General Task Process. In this article, we’ll take a look at
how these three actions work.

The first thing you will notice when you add any of these three actions to your workflow is that
in the Editor, they all look identical. In the following screenshot I have added an Assign Item for
Approval action to Step 1, and Assign Item for Feedback action to Step 2, and a General Task
Process action to Step 3.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 9


So, how can you tell them apart? You have to click on the Approval Process link for the action.
When you do this, you will see a new page where you can define and customize that overall task
process.

Let’s work our way around this page to explain what each section does.

Task Information

In the Task Information section there are only two options, you can change the name of the
Approval Process and the Owner of the task.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 10


Both of these can be changed by clicking on the information you want to change. The Name is a
meaningful name to you for this particular process. I recommend changing this to a descriptive
name that will help you remember later what this particular process is for and to keep the
various approval processes in your workflow distinct. The Owner is the owner of this process;
you’ll see where this comes into play when we get to the Settings section.

When you change the Name here it also changes the name in the workflow editor.

Task Outcomes

The Task Outcomes section, you can define the various outcomes for this particular process. If
you selected the Assign Item for Approval action, you will already have the options of Approved
and Rejected listed here.

If you want to add other options, you can click the New button to add a new option. In the
example here, I have added a Skipped option.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 11


The items you list here will be listed as separate buttons on the task form and will be displayed
in the Sequence order you select.

Task Form Fields

The Task Form Fields section allows you to collect other information in the task form. For
example, if something is approved or rejected, you probably want the person who is doing the
approving or rejecting to enter some notes about why they chose to approve or reject it.

By clicking the New button, you can add your custom data fields to the form. There is a short
wizard that will walk you through the process.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 12


If you click the Choose existing field button, you will get a dialog box where you can choose
from any of the Site Columns that are already available on your site. This can be incredibly
handy since you can define the column one time and then reuse it as needed.

Settings

There are only three options in the Settings section.

If you check the box for Only allow task recipients and process owners to read and edit
workflow tasks then those are the only people who can do those activities. Do you remember
when you could set the process owner in the Task Information box? Well, this is where that
process owner is used.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 13


There are also boxes to allow users to reassign the tasks and to change requests.

Customization

I’ve saved this section for last because it is probably the most complex of the five configuration
sections.

Clicking on the Return to Workflow link simply closes the Approval Process editing window and
returns you to the workflow Editor.

If you click on Change the completion conditions for this task process you will be taken to the
Check Exit Conditions section where you can see the underlying conditions that are part of this
activity. This is probably where you begin to see how powerful these new Approval Actions
really are. Here is a screenshot of the default page without making any changes:

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 14


You can add more conditions here if needed, add steps and generally modify the process as you
need.

If you click on Change the behavior of a single task you will be taken to a place where you can
see and change the behaviors for On Task Assigning, On Task Pending, On Task Expired, On Task
Deleted, and On Task Completed. Within each of these, you can add your own conditions,
actions, and steps. Here is a screenshot of the default page:

If you click on Change the behavior of the overall task process you will be taken to a place
where you can see and change the behaviors for On Approval Started, On Approval Running, On
Approval Canceled, and On Approval Completed. Once again, within each of these, you can add
your own conditions, actions, and steps. Here are screenshots of the various sections of the
default page:

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 15


Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 16
Whew! That’s a lot of options and configurations that you can do! But were not yet finished!
Remember that these were just the settings for the process. If you return to the workflow editor
you’ll see that there are still two more options we haven’t looked at yet.

Item to Be Approved

You probably expect that the only item on which you can perform the Approval action is the
current item. However, if you click on Current Item, you can change that to any list or library
item you want.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 17


Assigned to Users

Another thing that I found frustrating in SharePoint 2007 was that I couldn’t customize the task
and emails that they sent. When you click on the link in SharePoint 2010 to add users, you get a
dialog box where you can customize task request, including the title and body that can include
lookups. You can even add serial and parallel recipients and have multiple assignment stages.

Well, there you have it. You’ve gotten a general overview of the options for the new Approval
Actions in SharePoint Designer 2010. If you are overwhelmed, I’m not surprised. In this post,
we’ve only just barely scratched the surface of the great things you can do with SharePoint
Designer Workflows in SharePoint 2010. You’ll probably need to take a class to learn it all. 

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 18


The New Chart Web Part in SharePoint 2010 (Audience: All)
By Ricky Spears

I may have a new favorite web part in SharePoint 2010—at least it’s my favorite for a while.  I
am a bit of an Excel fanatic. I love drilling down into data to gain obscure business intelligence. I
love pivot tables, and I love graphs—although I’ll admit I’m much better at pivot tables than I am
graphing. It’s easy to get caught up in displaying your data in Excel—it becomes much more like
playing Excel than working with Excel. The new Chart Web Part is one of those fun web parts
that you can get caught up in playing with but it also solves the common business problem of,
“How can I quickly display a chart of some data on my SharePoint page?” Note: This article and
all screenshots are from the Technical Preview and things may change before SharePoint 2010 is
released to the public.

Excel services is a great way to render charts in SharePoint – just set up the chart in Excel and
then add an Excel Services web part to display the named chart from your published
spreadsheet. But with the Chart Web Part, you can not only chart information from your Excel
Services spread sheets, but also from any SharePoint list. And best of all, you configure
everything in your browser!

Adding the Chart Web Part to a Page

You’ll find the Chart Web Part in the Miscellaneous category and you add to your page just like
you would any other web part by selecting it and clicking the Add button.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 19


You will see that SharePoint 2010 adds the web part and it displays a new chart based on some
random data.

Configuring the Chart Web Part

With most web parts, you expect to configure them in the tool pane, although you can certainly
do that by clicking on Modify Shared Web Part, you will probably want to use the wizards to
configure it. You can access the list of wizards by clicking on Wizard List.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 20


The Chart Web Part Wizards

There are two wizards: one to Customize Your Chart, and one to Connect Chart to Data. We’ll
begin by using the Connect Chart to Data wizard and then we’ll customize our chart later.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 21


The Connect Chart to Data Wizard

The first step in the wizard is to choose a data source. Notice that you have the options to Get
Data From Another Web Part, Connect To a Site Definition List, Connect to Business Data
Catalogue, and Connect to Excel Services. This is a nice set of options. I have some Sales Data in
a SharePoint list and that’s what I want to chart, so I’ll select the option to Connect to a Site
Definition List.

In the second step of the wizard, I select the site where my data is stored and the list. Both of
these are displayed in drop-down list boxes and I can select lists and libraries anywhere in my
site collection—not just the one I’m currently working in, which is a very nice feature.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 22


In the third step of the wizard, it shows me a preview of the data that is available for charting.
Here is what it shows me for my 2009 Sales list:

Here is what the SharePoint list looks like if you view the default view directly:

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 23


In the fourth and final step of the wizard, I bind the chart to the data. You’ll notice that there is
an impressive set of options—you can configure this connection in almost any way you can
imagine.

For this blog post I used 4 series that were each set up to display a unique quarter (Q1 Sales, Q2
Sales, Q3 Sales, and Q4 Sales). You can’t see these all at once, so I’m not adding screenshots. I
didn’t add any other Data Point fields, Formulas, or change the Advanced Properties. At this
point, I had finished the Connect Chart to Data wizard. I could see my data displayed in the Chart
Web Part.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 24


It was nice to see my chart rendered so quickly, but I wanted to change the way it looked, so I
ran the Customize Your Chart wizard.

The Customize Your Chart Wizard

This is the wizard that will allow you to change the way your chart looks. Once again, you have a
very impressive number of options here.

The first step is to select a chart type. I counted 158 different types of charts! You have two
dimensional and three dimensional charts in types of column, bar, area, line, point/bubble,
financial, pie, radar, polar, Gantt/range column, range, error bar, box plot, funnel, and pyramid. I
know that with this set of options, it’s kind of boring, but I selected the Column with Perspective
as my chart type. It just seemed appropriate for this kind of sales data.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 25


In step two I changed the appearance of the chart. There are 12 themes you can choose from:
Bright Pastel, EarthTones, LightSteelBlue, GreyScale, SemiTransparent, ExcelLike, LightBeige,
Berry, Chocolate, Fire, GreenBlue, and Custom. I selected the LightBeige just because I liked it.
For Drawing Style, you can select from Default, Cylinder, Emboss, LightToDark, and Wedge. I
selected Cylinder. Transparency can be set from 0% - Solid to 100% - Invisible. I left it at the 20%
default. For the Size and Format I could set a custom chart width, chart height, and even image
format (JPG, BMP, or PNG)—I left all three of these set at the defaults. One of the things I really
like about the Chart Web Part is that it generates an actual image on the page and not
something that is rendered by AJAX or ActiveX or SilverLight. Since it’s an actual image, I can
easily copy and paste it into another document, or email, or even save the image if I want.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 26


At this point I’m finished with both of the wizards and I can see my finished chart on the page

Advanced Properties

The only thing I haven’t shown you yet is the Advanced Properties. If you click on this link, you
can view a properties dialog where you can change various properties of the image itself like
antialiasing, shadows, border line colors, and much more.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 27


So, what are you waiting for? You know you want to play some at work, so go ahead and add a
Chart Web Part to your SharePoint 2010 site and start playing around. You can tell your boss I
said it was OK. 

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 28


Creating SharePoint 2010 Workflows in Visio 2010 (Audience: All)
By David Fisher

Microsoft is taking a bit of the chore of designing workflows off of designers and letting business
users define their own workflow layout in Visio 2010 before exporting to SharePoint Designer to
associate it with a List or Site. This allows business users to use a familiar graphical tool to define
the steps in the workflow themselves instead of having to communicate their needs to designers
or developers through a requirements document. The resulting Visio workflow can be used as
the actual initial building block in the workflow.

Visio includes a brand new template aptly called Microsoft SharePoint Workflow that includes
Condition and Activity shapes specific to SharePoint workflows.

Visio Conditions, Activities and Terminators

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 29


Not all of the Conditions and Activities currently match up to those available in SharePoint Designer.

Note: This information is currently based on Technical Previews of both Visio 2010 and
SharePoint Designer 2010 and both are subject to change in the Beta version due out later this
year. It is also important to note that Designer connects directly to the SharePoint site and
retrieves a list of available conditions and activities currently installed on the site including any
created in Visual Studio and any 3rd party installed solutions, whereas Visio does not; the list
available in Visio is static in this preview version. The ability to connect to the target site in Visio
would be a great addition and would help to allow business users to build a more complete
workflow ready for installation into a SharePoint site.

Creating a workflow will come naturally to users familiar with creating charts in Visio using drag
and drop from the Shapes tabs and connecting them on the workspace, with the only difference
being the SharePoint specific shapes. Below is an example of a simple workflow created in Visio
2010.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 30


Visio currently does not include any Shape Data on any of the shapes, meaning that although
you can drop a "Send an Email" activity onto the workspace, you cannot specify any of the
properties on the activity such as the To address, Subject or email Body. A designer will need to
import the workflow into SharePoint Designer for final configuration and publishing to a list or
site. I will show shortly how Visio stores attributes for the shapes when exporting the workflow.
The addition of the shape data would be the final piece that would allow business users to build
a complete workflow ready for publishing and I am hopeful that this will be included in the beta
and/or final release of Vision 2010.

After completing the workflow, it is necessary to check it for errors in logic. Visio 2010 includes
the "Check Diagram" option from the Process tab of the Ribbon.

By default, the Check Diagram feature includes the "SharePoint Workflow" option as the rule
base to check the workflow against. Clicking on "Check Diagram" will result in Visio checking the
logic against SharePoint's rules and will either notify that no errors where found or give a list of
errors in the Issues Window below the workspace. Clicking on an issue will highlight the
offending object making it easier to determine the cause and fix the problem.

Example of an error in the Issues window.

After successfully checking the workflow, you now must export it to the file system so that it can
be imported into SharePoint Designer. On the Process tab of the Ribbon are the Import and
Export buttons. Import allows you to open workflows created in SharePoint Designer for graphic
representation and documentation. Since it is possible to create a workflow in Designer that

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 31


uses activities built in Visual Studio that Visio does not know about, those activities show up as a
generic Activity with the name "Custom Action".

Exporting is as easy as clicking the Export button and choosing a filename and location. Visio
2010 will save the workflow with a .vwi extension. By simply renaming this file with a .zip
extension you can open it and reveal the following 4 embedded files.

[Content_Types].xml

This file simply stores a list of the extensions of the files embedded in the .vwi file.

workflow.vdx

This is the Visio definition file for the workflow including file properties and layout details for the
workspace. When building a workflow in Designer, you will notice each condition or activity
includes a sentence where you set properties for its parameters. This file contains the text for
those sentences for use when importing the workflow into Designer.

workflow.xoml

Designers and developers familiar with creating workflows in SharePoint Designer will be
familiar with this file. It is an XML representation of the workflow including all conditions and
activities and their parameters. Although Visio does not include shape data on the workspace,
when exporting the workflow, the appropriate parameters will be included in this file. When
importing the workflow into Designer, it uses this file to get the logic for the workflow as well as
all of the parameters and values for each condition and activity. The exported file will have the
value {x:Null} set for each parameter since there is no way to set these in Visio.

Here is a sample .xoml file as created when exporting the workflow shown above. The
SequenceActivity section has been highlighted to show how the workflow logic including the
conditions and activities is written to this file.
<ns0:RootWorkflowActivityWithData x:Class="Microsoft.SharePoint.Workflow.ROOT"
x:Name="ROOT" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/workflow"
xmlns:ns1="clr-
namespace:Microsoft.SharePoint.WorkflowActions.WithKey;Assembly=Microsoft.SharePoint.Work
flowActions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=null"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ns0="clr-
namespace:Microsoft.SharePoint.WorkflowActions;Assembly=Microsoft.SharePoint.WorkflowActi
ons, Version=14.0.0.0, Culture=neutral, PublicKeyToken=null">

<ns0:RootWorkflowActivityWithData.WorkflowFields>

<ns0:WorkflowDataField Name="__list" Type="System.String" />

<ns0:WorkflowDataField Name="__item"
Type="Microsoft.SharePoint.Workflow.SPItemKey" />

<ns0:WorkflowDataField Name="__context"
Type="Microsoft.SharePoint.WorkflowActions.WorkflowContext" />

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 32


<ns0:WorkflowDataField Name="__initParams"
Type="Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties" />

<ns0:WorkflowDataField Name="__workflowId" Type="System.Guid" />

<ns0:WorkflowDataField Name="calc" Type="System.Double" />

</ns0:RootWorkflowActivityWithData.WorkflowFields>

<ns0:OnWorkflowActivated x:Name="ID1" WorkflowProperties="{ActivityBind


ROOT,Path=__initParams}">

<ns0:OnWorkflowActivated.CorrelationToken>

<wf0:CorrelationToken OwnerActivityName="ROOT" Name="refObject"


xmlns:wf0="http://schemas.microsoft.com/winfx/2006/xaml/workflow" />

</ns0:OnWorkflowActivated.CorrelationToken>

</ns0:OnWorkflowActivated>

<ns0:ApplyActivation x:Name="ID2" __Context="{ActivityBind ROOT,Path=__context}"


__WorkflowProperties="{ActivityBind ROOT,Path=__initParams}" />

<SequenceActivity x:Name="ID3">

<IfElseActivity x:Name="ID4">

<IfElseBranchActivity x:Name="ID5"
Description="ShapeGuid={5C21D244-2AB1-4447-A2BA-CE6431839784};PageId=0;ShapeId=4;">

<IfElseBranchActivity.Condition>

<RuleConditionReference ConditionName="__Rule_ID5"
/>

</IfElseBranchActivity.Condition>

<ns0:EmailActivity x:Name="ID6" __Context="{ActivityBind


ROOT,Path=__context}" To="{x:Null}" Subject="{x:Null}" Description="ShapeGuid={268E5AD8-
F73D-4519-A56D-62246EAA3B33};PageId=0;ShapeId=8;" BCC="{x:Null}" CC="{x:Null}"
Body="{x:Null}" />

</IfElseBranchActivity>

<IfElseBranchActivity x:Name="ID7">

<ns1:SetFieldActivity x:Name="ID8" __Context="{ActivityBind


ROOT,Path=__context}" Description="ShapeGuid={560EFD0C-3C56-41B6-BA1C-
723C4ADE3FDD};PageId=0;ShapeId=12;" FieldName="{x:Null}" __ListItem="{ActivityBind
ROOT,Path=__item}" __ListId="{ActivityBind ROOT,Path=__list}" />

</IfElseBranchActivity>

</IfElseActivity>

</SequenceActivity>

</ns0:RootWorkflowActivityWithData>

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 33


workflow.xoml.rules

This file defines the rules used when checking the workflow for errors.

SharePoint Designer leaves behind the old look and feel of FrontPage; in 2010, it fits right in with
the Office suite. In this technical preview, there are a few pieces that are not as obvious to
access and even completely hidden and this is bound to get under the skin of technical designers
and developers. However, my thoughts are that most of them may likely make their way into
the public release due out by the time of this writing. I will only discuss those features
associated with workflows in this article.

To see the list of workflows for the loaded site, simply click Workflows on the left Navigation
bar.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 34


Importing a workflow from Visio 2010 is as easy as going to Workflows on the left Navigation bar
and then clicking the "Import from Visio" link in the new Ribbon at the top of the window. You
are prompted to locate the .vwi file created by Visio 2010 and to name and associate the new
workflow with a list on the site, or to make it a Reusable workflow.

After importing the previous workflow shown in Visio, you come to the Edit screen for the
workflow where you can define the values for the parameters as well as add additional
conditions and activities.

The Ribbon is context specific and now contains buttons for building and publishing the
workflow. The Manage section includes buttons for Checking for Errors, Publishing the workflow
and exporting as a .vwi file to Visio.

The Modify section includes buttons for moving activities around in the workflow as well as an
"Advanced Properties" button where you can set the parameters for the selected condition or
activity. This allows you to set values for the parameters directly as opposed to using the
standard DesignerType. Clicking on the parameter in the sentence allows you to set the values
using the DesignerType pop up window.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 35


Example of using the Advanced Properties button from the Ribbon to set parameter values

Example of using the DesignerType pop up window to set parameter values

The Insert section includes buttons for editing the logic of the workflow; inserting steps,
conditions and actions, running sections in parallel and adding steps that use Impersonation to
run as the workflow author.

Lastly, the Variables section includes a Forms Parameters button to define parameters used to
gather data from the user on the Initiation and Association forms when the workflow runs. It
includes the Local Variables button for creating variables for use within the workflow and that
can be accessed as lookups on the workflow. The Variables section also includes an Association
Columns button which allows you to automatically create columns on a list when the workflow
is associated with it. The purpose of this is to make sure that these columns exist if the workflow
depends on them for setting or gathering data.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 36


The next logical step is to configure the parameter values in the workflow. As stated before,
Visio 2010 does not include shape data for the shapes, however it does include all of the proper
parameters in the .xoml file when exporting the workflow so they show up properly when
importing into Designer. This is done by either using the Advanced Properties button or clicking
on each parameter and using the pop up windows as described earlier.

Clicking on the Publish button validates the workflow for errors, saves the .xoml file and makes
the association with the list in the content database. One of the options missing that developers
in particular may miss is the fact that there is currently no way to view the .xoml in Designer as
there was in 2007. You will have to Export to Visio to produce the .vwi file to get access to the
xoml code. If you make any changes to it, you will need to import the .vwi back into Designer.

When Publishing the workflow I have come across some errors in validation associated with the
DesignerTypes in 2010. Some changes have been made in the DesignerTypes that will be the
topic of another article. Workflows built in Visio 2010 should not be affected, but any existing
conditions or activities built in Visual Studio will.

The next logical step that does not show up in the Technical Preview of Visio 2010 is the ability
to create custom conditions and activities in Visual Studio and import them into Visio as well as
the addition of shape data for the shapes in Visio 2010. With this new template addition,
business users should enjoy the ability to create their own workflows knowing that what they
build will actually become the core of the workflow they will end up using on the SharePoint
site.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 37


SharePoint 2010 * Windows PowerShell = Disaster Recovery2
(Audience: IT Admins)
By Eric Eaton

There were many options for disaster recovery with WSS 3.0 and MOSS 2007. The native tools
all had significant advantages, and unfortunately, disadvantages. Methods that offered the best
protection against full-scale disasters offered little to no granular protection against more
common ‘accidental deletion’ moments. STSADM, the SharePoint command-line administration
tool, offered the only native way to schedule backups by means of simple batch files – but it was
painfully slow and many times marked the site collection read-only as it worked.

Because of these limitations, many organizations either used multiple types of backups to
protect against different scenarios, or relied on third-party products to fill the gaps (or even to
completely replace the native tools).

With the new SharePoint 2010 functionality, these limitations no longer pose significant
obstacles. With enhancements to Central Administration’s backup / restore tools and the
addition of Windows PowerShell cmdlets to our command-line tool belt, it is now possible to
cover most issues and / or scenarios with a single disaster recovery scheme that protects your
SharePoint configuration and data from both granular, accidental deletions and true large-scale
disasters.

Big Picture

This post is specifically addressing the backup and recovery of SharePoint configuration and data
– not A.D. or other directory providers, your server environment, branding, and programmatic
customizations such as features and solutions. The strategy for protecting those elements will
vary greatly depending on your organization’s overall disaster recovery strategy which may
include traditional tape backup, virtual machine snapshots, server imaging, off-site replication,
shared software installation points… At the very least, you should have a copy of all installed
solution packages stored and backed up with the rest of your installation media.

Obviously, to offer any kind of protection against large or small scale disasters, backups must
occur regularly and automatically. To schedule backups of SharePoint data, an administrator
has two options – SQL and PowerShell. SQL does not offer full configuration backup on its own
– but PowerShell does.

In fact, SharePoint 2010 adds about 300 new cmdlets that provide a much more flexible,
interactive, and granular tool for SharePoint than STSADM ever did. Several of these cmdlets
provide the same backup functionality available manually through the Central Admin site,
including the ability to pick and choose which farm elements to backup / restore. An

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 38


administrator can now schedule regular backups of SharePoint content and configuration
completely via Windows PowerShell and Scheduled Tasks, and then perform granular restores
(down to the individual list level) through the web GUI available in Central Admin if he prefers.

The Nitty Gritty…

Let’s take a look at the Central Admin ‘Backup and Restore’ page to see what is possible here.

Login to your SharePoint server, and go to Start > Administrative Tools > SharePoint 4.0 Central
Administration.

Click on the first displayed link, ‘Perform a backup’, and you’ll see a tree view of all farm
elements. Notice that this includes the configuration database, web application setup, content
databases, service applications, user profiles… Pretty cool, eh?

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 39


Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 40
Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 41
This same tree-view is shown during a restore, so that on either end of the process the
administrator can select all or any part(s) to work on. These component names in the first
column can also be shown and referenced in the PowerShell environment by the same names.
To open the SharePoint PowerShell environment:

Go to Start > Administrative Tools > SharePoint 4.0 Management Console (SMC). (This may
take a moment to load, don’t get impatient.) Type the following to display the components
hierarchically by name: Backup-spfarm -showtree.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 42


Why do we care? The backup-spfarm cmdlets includes a parameter that allows us to select
individual items instead of the entire farm.

To see some basic help text on the usage, type: backup-spfarm -?. (A complete
reference of the –detailed text of all SharePoint PowerShell cmdlets is being built at
http://sharepointsolutions.com/sharepoint-help/groups/sharepoint-2010-powershell-
reference/home/).

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 43


For this basic backup requirement, we need to create a full backup of the entire farm.
Type: backup-spfarm –directory \\fileserver\backupshare -
backupmethod full.

If your datasets are too large to do a full farm-level backup every day, you may wish to do this
weekly and then back up only the content nightly. To create a backup of just a content database
type the following command in the SMC:
Backup-spfarm –directory \\fileserver\backupshare -item “name as
listed in tree above” –backupmethod full

In the background, these backup commands are using different backup methods to protect
different components. For instance, the content is backed up via a remote SQL database backup
statement. A complete log of the backup attempt is kept in the ‘spbackup.log’ file in the backup
directory you specified in the command above. If there are any warnings or errors, the SMC will
give a generic message that ‘The backup job failed…’ That doesn’t mean the entire job failed,
but you will have to check the log file to find out where the problems were encountered.

Now that you know how to form the basic SharePoint PowerShell commands, the next step is to
schedule them. This process is made up of a couple of steps.

Configure PowerShell to allow scripts. In the SMC, type:


set-executionpolicy RemoteSigned

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 44


Create a PowerShell script (.ps1 file extension) containing a couple of standard lines necessary
to load the SharePoint cmdlets and then the command(s) we just tried above. (Below is an
example based on backing up just a single content database.)

If you need to clear previous backup directories to conserve disk space, you can do this in your
ps1 PowerShell script, as shown here.

Here are the steps to use the Task Scheduler functionality in Windows 2008 Server to schedule
your script to run on a daily basis. (If you are using Win2k3 as your OS, the steps are similar but
they would be done in the older style Scheduled Tasks tool.)
Go to Start > All Programs > Accessories > System Tools > Task Scheduler, and click on the
Create Basic Task… link on the right side.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 45


Type a descriptive name, and click Next.

Click the Daily button, and click Next.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 46


Enter your desired daily start time, and click Next.

Click the Start a program button, and click Next.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 47


Type powershell in the Program/script blank, and then -command "& „your ps1
file path and name‟ " in the Add arguments (optional) blank.

Click Next and Finish.

If you have multiple PowerShell scripts to run (for full & differential, or farm-level & content db’s
only), then you would schedule each script separately using this same method. In most
organizations, I recommend starting with weekly PowerShell full farm-level backups, and nightly
PowerShell backups of content databases. One advantage of scripting these backups via
Powershell is the ease of multi-threading. The Backup-SPFarm cmdlets includes a ‘–threads’
parameter, and by putting each content db backup in its own script you can schedule them
independently where each one starts with its own thread. That also allows you the flexibility to
backup some content databases more frequently than others.

That’s all you require to create useful, inclusive, and granular restore capability for your 2010
SharePoint farm. A big part of the reason this is so powerful though, is on the restore side of the
equation. Look for a follow-up post that describes in detail how to use Central Admin and / or
PowerShell to restore what you have painstakingly backed up.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 48


SharePoint 2010’s New Granular Content Restore Capability
(Audience: IT Admins)
By Eric Eaton

In a previous post, I documented some of the exciting new functionality that PowerShell
provides for backing up a SharePoint 2010 farm. Now, let’s look at the other side of the coin –
restoring.

Restoration is usually needed in one of three basic scenarios:

1. A user has deleted or messed up some critical content.


2. An administrator has had a configuration mishap.
3. A natural / man-made disaster or hardware failure has completely taken down the farm.

The way you would go about recovering from each of these scenarios would be very different.
In this post, I’ll address the first – Content Deletion. I’ll do a follow-up post to address the
admin-level mishaps and recovery from a true disaster.

For now, let’s pretend that some well-meaning power user has been trying to clean up the Logos
library in our root site to eliminate redundancy and recover some space within our quota.
However, they have inadvertently deleted the logo used as our site image – and in a quest to be
thorough they’ve deleted it from both Recycle Bins before they noticed the problem.

We can now use the Central Admin site to look for a content database backup that predates the
deletion, and then restore the content at as small of a scale as possible.

Go to Start > Administrative Tools > SharePoint 4.0 Central Administration, and then click the
Backup and Restore link on the left.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 49


Click on the ‘Restore from a backup’ link in the top section of the page, select the appropriate
backup from the list, and click Next.
(If you don’t see your backup listed, try changing the Backup Directory Location entry and
clicking the Refresh button.)

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 50


Drill down through the hierarchy displayed to find the content database you need, and check
the box to select it. Then click Next.

Select New configuration, and enter either a new directory name, database name, or server
name. Then click the Start Restore button.

The timer service will now schedule and immediately run a job that asks the back-end SQL
server to restore the old database without overwriting the live one. The time it takes will
obviously vary according to the size of the database and the concurrent activity on the SQL
server. The Job Status page will likely eventually show an error related to attaching the
database to the Web Application. That’s not a problem – we didn’t want the old database to be

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 51


attached anyway.
(Note: You cannot restore over an existing database. You must either specify a new name /
server or delete the previous database.)

Return to the Backup and Restore page via the left-hand navigation pane, and click the Recover
data from an unattached content database link in the bottom section.

Enter the Database Server and Database Name, choose to Export site or list, and then click
Next.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 52


Select the relevant Site Collection, Site, and List, enter a Filename (and path), and versions that
you need. Then click Start Export.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 53


The Job Status screen will hopefully show a Succeeded message, and tell you that the cmp file is
ready to be imported using PowerShell.

Go to Start > Administrative Tools > SharePoint 4.0 Management Console, and type the
following command:
Import-SPWeb –Identity http://yourportalURL –Path
filenameandpathtocmpfile –Updateversions 3

This one felt a bit disconcerting to me at first, but we have to understand how the cmp file and
the import command work. Notice the command is Import-SPWeb, not SPList. This is why it

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 54


only asks us for the web application identity instead of the web or list identity. The cmp file we
exported earlier contains the path all the way to the list and what’s available for importing (the
contents of a single list in this example). Therefore, when the import command goes to read the
cmp file, it is willing to import anything it contains – but only finds the items in the Logos library.
The –Updateversions 3 parameter allows us to only restore items that don’t exist in the live
library, ignoring the items that already exist. (For a complete explanation of the Import-SPWeb
cmdlet, its parameters, and its usage, see its topic in the online SharePoint 2010 PowerShell
Reference forum.)

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 55


SharePoint 2010’s New Configuration Restore Capability
(Audience: IT Admins)
By Eric Eaton

In a short series of articles I’ve been documenting some exciting new disaster recovery
functionality included in SharePoint 2010. (As a side note, this may be the only Google search
that you could do that contains both ‘exciting’ and ‘disaster recovery’ in the same sentence…)

Restoration is usually needed in one of three basic scenarios:

 A user has deleted or messed up some critical content.


 An administrator has had a configuration mishap.
 A natural / man-made disaster or hardware failure has completely taken down the farm.

The way you would go about recovering from each of these scenarios would be very different.
In a previous post, I addressed the first – Content Deletion. Now let’s talk about the admin-level
mishaps and recovery from a true disaster.

Admin-Level Mishaps

There are many times we as admins make a change to a farm’s configuration that seems logical
at the time, but messes up something else in unanticipated ways. Sometimes these changes are
very large and / or complex and therefore difficult or impossible to put back manually. If you’ve
been performing scheduled full farm backups via PowerShell, or even just done a manual
backup beforehand in the Central Admin site, you can usually find a way to restore just the
affected pieces. Let’s pretend that our boss’s nephew who’s spending the summer as our IT
intern has messed up the configuration of our search content sources. (Of course WE wouldn’t
have messed it up…)

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 56


Go to Start > Administrative Tools > SharePoint 4.0 Central Administration, and then click the
Backup and Restore link on the left.

Click the Restore from a backup link in the top section, then pick the relevant full farm backup
from the list provided and click Next.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 57


Scroll through the list of components to find the Search Service Application, select it, and then
click Next.

Select the Same configuration button to overwrite the existing, wrong configuration and
replace it with the known good configuration from the farm backup. This will cause one of
those ‘are you sure’ kinds of prompts. Just click OK and then click the Start Restore button.

That should do it. The job will take a few minutes to complete, but when it does, your content
sources will be restored to their previous condition.

This restore operation could also be done via PowerShell using the Restore-SPFarm cmdlets with
the –Item parameter. (See its topic in the online SharePoint 2010 PowerShell Reference forum
for more information.)

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 58


Total Farm Rebuild

Whether it’s a natural disaster like a flood, hurricane, tornado, or earthquake or a man-made
one like a building fire or hardware failure – we must think ahead to the possibility of losing our
entire farm. The PowerShell full farm backups you’re running on a scheduled basis, and possibly
the PowerShell content database backups too, can rebuild all of your configuration and content.
Let’s think happy thoughts, and pretend that only the SAN holding our virtual server drives died
instead of picturing a wall of water through our town. What do we do now?

There are many external and / or third-party solutions used to protect entire servers. Let’s
assume in this example that we have none of that. We are starting with a blank Windows 2008
Server image and we need to get our portal operational as soon as possible. We are assuming
that we have the following at our disposal:

 A fully restored and functioning Active Directory


 The installation media for SharePoint 2010 and any third-party or custom developed
solutions that we were using pre-disaster
 A copy of our SharePoint backup directory that has been dumped onto our new server
or a file share via tape backup

(IMPORTANT: Including the spbrtoc.xml. This is your backup history file, and without it
you are toast. Make sure you do not delete this file accidentally when reclaiming disk
space, and make sure your off-site backups include it from the root backup directory.
The spbr##### folders ARE NOT ENOUGH by themselves.)

Now what?

Reinstall SharePoint from the installation media, and run the initial SharePoint 4.0 Products and
Technologies Configuration Wizard to create a farm and configuration database.

The Central Admin site should open automatically and begin the web-based Farm Configuration
Wizard. (If not, you can find it by going to Start > Administrative Tools > SharePoint 4.0 Central
Administration, and choosing Configuration Wizards from the left-hand navigation.)

(Now this feels a little counter-intuitive to me, but it is a good idea to let this wizard start up all
of the relevant service applications before performing your restore. When I did not do this, I
received errors as the restores tried to configure the web and service applications from scratch.
If you opt not to run the wizard before the restore, you can do so after the restore completes to
catch any service applications that did not restore successfully. However, you may have to
restore and run the wizard multiple times to get everything to finish.)

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 59


Choose to ‘Walk me through…’ and click Next.

Choose an existing managed account or enter one in the blanks provided, select all service
checkboxes, and click Next.
(If you are restoring a multiple-server farm, you would need to perform steps 1-3 on each server
– starting only the relevant service applications on each server in turn.)

When the ‘Processing…’ page completes, the wizard will give you the option to create a new site
collection. Click the Skip button and then the Finish button.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 60


If you have any third-party or custom-developed solutions / features to install – now would
usually be the best time.

Now you are prepped for the farm restore. You could do this using a process very similar to the
one documented and illustrated in section ‘2. Admin-Level Mishaps’ above. The only difference
would be selecting all components in the tree instead of one. For a little variety though, we’ll do
this restore using Windows PowerShell instead.

Go to Start > Administrative Tools > SharePoint 4.0 Management Console, and type the
following command:

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 61


restore-spfarm –directory yourbackupdirectory –restoremethod
overwrite –percentage 1

(For a complete explanation of the Restore-SPFarm cmdlet, its parameters, and its usage, see its
topic in the online SharePoint 2010 PowerShell Reference forum.)

The SMC window will prompt you to verify the action and the overwrite, and eventually to enter
credentials for your user web applications.

That should restore all relevant content and configuration to your SharePoint 2010 farm. Like
most disaster recovery situations – your mileage may vary according to the complexity of your
environment, the integrity of your backup data, and a million other wrinkles you couldn’t have
seen coming. If the SMC window gives you an error message, the sprestore.log file in your
backup directory will give you more detailed information about the problem encountered. In
my own trial runs with this functionality, I did receive an error now and then. Usually they had
to do with a file or some other dependency not being available. In some cases simply running
the restore-spfarm cmdlets again was successful the second time. In other cases I had to start
the problem service application through the Central Admin site and its web-based Farm
Configuration Wizard, and then run the restore again to inherit my previous configuration.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 62


Creating a Custom Ribbon Tab in SharePoint 2010 (Audience: .NET
Developers)
By Jeremy Luerkens

Introduction

As a SharePoint developer, mirroring the style of the SharePoint user interface in a custom
application is important to create a homogeneous experience for your end users. One of the
best opportunities to accomplish this is by creating a custom ribbon tab containing
contextualized buttons to suit your application.

In this article I’ll show you how to define a new SharePoint Ribbon Tab which includes a button
group and a collection of ribbon buttons like Laugh and Giggle. I’ll discuss how to extend the
CUI.Page.PageComponent JavaScript object to quickly configure ribbon button command
actions. Finally I’ll discuss how to make your custom ribbon tab available from a Layouts page.

Deploy a Custom Ribbon Tab Definition

We begin by deploying a custom ribbon tab definition to your SharePoint environment. This is
done using the <CustomAction /> element of a SharePoint feature. We begin by defining a
<CustomAction /> element with the location of ‘CommandUI.Ribbon.Tabs._children’. This will
add our custom ribbon tab defined in the <CommandUIDefinition /> element to the collection of
available SharePoint ribbon tabs.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 63


Coordinate the Ribbon Tab Using a CUI.Page.PageComponent

A SharePoint ribbon tab is comprised of HTML and JavaScript elements. Buttons residing on the
ribbon tab are coordinated using JavaScript methods. By following the template used on many
of the SharePoint pages we can easily set up the necessary JavaScript methods to orchestrate
our ribbon events.

The first step is to create a JavaScript object containing the appropriate JavaScript methods to
coordinate the ribbon tab buttons. We start by creating a file named RibbonApp.UI.js and
provide an object definition for our custom ribbon page component named
‘RibbonApp.UI.RibbonAppPageComponent’. This JavaScript object derives from
‘CUI.Page.PageComponent’ and provides the necessary methods to coordinate the ribbon tab
buttons.

The most important methods of the RibbonAppPageComponent can be found in the prototype
definition. Inspecting the methods below you will notice calls to global JavaScript functions
getGlobalCommands, commandEnabled and handleCommand.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 64


This sample RibbonAppPageComponent provides a basic framework to support your ribbon
tab’s custom commands. The RibbonAppPageComponent can be reused by all of your custom
ribbon tabs and it is not necessary to create a custom PageComponent for each tab. However,
creating a custom PageComponent to alter or customize the behavior of a specific ribbon tab
may be a good option in select circumstances.

Adding the Ribbon Tab to a Page

Once the ribbon tab is defined and the page component created it is time to add the ribbon to
your SharePoint .ASPX page. We start by creating a private method named InitializeRibbon
which gets called from the Page_Load method of our SharePoint page. We begin the method by
getting a reference to the current SPRibbon element and check to ensure the current ribbon is
not NULL.

Once we have a reference to the current ribbon we can begin defining the ribbon behavior. We
start by setting some basic ribbon properties and adding the available tabs. The Id passed to the
MakeTabAvailable method must match the value defined in our ribbon tab definition. We can

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 65


also set up the initial ribbon tab. A common tab added to most pages is the ‘Ribbon.Read’
element which provides the page title and description.

The ribbon uses the ‘SP.js’ and ‘SP.Runtime.js’ JavaScripts. To ensure these scripts are registered
on our page we make two calls to the RegisterScriptAfterUI method. We would also like to
register our RibbonAppPageComponent. The SPRibbonScriptManager contains a method to
register this script and call the initialize method after the page is loaded. Unfortunately access to
this method is private. To correct this deficiency we created our own RibbonScriptManager class
to register and initialize the RibbonAppPageComponent.

Finally we need to wire up our ribbon buttons to perform meaningful operations. This is
accomplished by creating a list of IRibbonCommands. The simplest ribbon command can be
created with the ribbon command name, JavaScript action command and JavaScript enabled
command. In the code below we are going to register the Laugh button which has a hardcoded
enabled value of ‘true’. When the button is clicked we send an alert to the user.

The enable JavaScript string could easily be turned into a JavaScript method which might inspect
the page state to determine button availability. This can be seen in the JSEnableDisable button
which defines the enabled script to IsJSEnabled(). The IsJSEnabled() method corresponds to a
JavaScript method placed on the page to determine the button state. If a Boolean value of true
is returned from the method the JSEnableDisable button will be clickable. If a Boolean value of
false is returned the JSEnableDisable button will be disabled.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 66


The final important take away from the script below is the RegisterGetCommandsFunction,
RegisterEnabledFunction and RegisterHandleCommandFunction. These are set to the JavaScript
method names defined in our RibbonAppPageComponent. The contents of these methods are
derived from the list of commands passed to these methods.

Your ribbon tab is now ready. Build and deploy your application to your SharePoint environment
and enjoy the fruits of your labor. If you make a lot of changes to your ribbon you will notice IE
caches a lot of ribbon content. It may be necessary to delete your cached files after an update or
turn off caching all together.

Additional Ribbon Commands

The SPRibbonCommand is used to interact with page components via JavaScript. Other
SPRibbonCommands can be used to provide alternate types of interactions. Other ribbon
command types available are the SPRibbonPostBackCommand, , SPRibbonQueryCommand and
the SPRibbonPopulateQueryCommand. .NET programmers are accustomed to creating buttons
which post back to a code behind page where additional programming actions can be taken. To
do this we leverage the SPRibbonPostBackCommand.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 67


To handle the post back event our page must implement the IPostBackEventHandler. The
implementation of the RaisePostBackEvent begins by deserializing the SharePoint ribbon post
back event and handling the post back ID provided by our post back command.

Conclusion

The ribbon is new to SharePoint 2010 and is being embraced by Microsoft. The ribbon is making
its way into many Microsoft applications like the Office Suite, WordPad, Paint and Windows 7.
Consumers of Microsoft products, including SharePoint users, will come to expect a ribbon
driven menu to be included in custom applications.

Creating a custom ribbon tab for your SharePoint application doesn’t have to be a pain and can
be accomplished by defining a ribbon tab definition, creating a PageComponent to coordinate
ribbon events, and initializing the ribbon in your application page. Using a custom ribbon tab is
an excellent way to present custom actions in your application while maintaining a cohesive
visual experience for your users. Wow your users by including a custom ribbon tab in your next
SharePoint application.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 68


Create a Custom SharePoint 2010 Picker (Audience: .NET
Developers)
By Jeremy Luerkens

Introduction

One of SharePoint’s neatest features is the People Picker. It allows a SharePoint user to
elegantly query, identify, and select SharePoint accounts. Did you know the People Picker is built
on a set of publically available picker controls available to every SharePoint developer? Read the
rest of this article to find out how to include a custom picker into your new SharePoint
application.

Cast of Characters

Developing a custom SharePoint picker involves the creation and orchestration of three
components, the Editor, Picker Dialog, and the Query.

Editor

The editor provides an entry point for the user to express the selected entities. It also provides a
launch pad to open a popup picker dialog box and search for entities. The editor class derives
from Microsoft.SharePoint.WebControls.EntityEditorWithPicker.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 69


Picker Dialog

The picker dialog is a popup window which appears when the SharePoint user wants to search
for one or more entities. This dialog box can be opened by clicking the editor’s browse button.
By default the picker dialog is setup to take a search expression and display the matches in the
results panel.

The picker dialog class derives from Microsoft.SharePoint.WebControls.PickerDialog.

Query

The Query control provides the visual results component of the picker dialog. This is the class
responsible for accepting the search criteria, obtaining a list of matching entries, and creating
the table of matching entries to be displayed inside the picker dialog. The query class derives
from Microsoft.SharePoint.WebControls.PickerQueryControlBase.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 70


Entity Model

Before any of the picker components can be developed we need to identify an entity object to
represent the selected data. A simple city entity can be represented with the following model.

Bringing the Picker Controls to Life

Once an entity is defined the editor, picker dialog and query controls can be created. Each picker
control has references to the other two controls which creates a dependency between each
control. As a result, creating the three controls before defining the control body simplifies the
process. We begin by creating a class named CityEditor which derives from
Microsoft.SharePoint.WebControls.EntityEditorWithPicker. Second, we create a class named
CityPickerDialog which derives from Microsoft.SharePoint.WebControls.PickerDialog. Finally, we
create a class named CityQueryControl which derives from
Microsoft.SharePoint.WebControls.PickerQueryControlBase. The three city picker controls have
the following properties and methods.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 71


Editor

The editor provides an entry point for the user to express the selected entities. The main job of
the Editor is to validate entities provided by the user and provide a launching pad to open a
picker dialog box to search for entities. We start by setting up the picker dialog by setting the
PickerDialogType property to the type of our CityPickerDialog class. This informs SharePoint to
use the CityPickerDialog control when searching for new cities.

We then want to define how entities are validated by our city picker. We do this by overriding
the ValidateEntity method. In this method we inspect each city provided by the user. If the city
is not already resolved we look for a matching city in the AllCities property of the CityManager
class. If a valid city is found we mark the city resolved. If not city is found we return the city in
the current unresolved state.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 72


The remaining CityEditor methods are used to convert entities between a City and a PickerEntity
and allow a programmer to set an initial list of selected cities.

Picker Dialog

The picker dialog control is the simplest picker class to create. It is used to set up the dialog
window properties and the column properties used by the search results. We start by defining
the results control used to display the matching cities.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 73


Most of work is done in the constructor where we set the results controls column display
names, column names and column widths.

Using the OnLoad method we set up the title and description of the dialog window.

Query

The query control is used to issue queries and return the results to the picker dialog. The
CreateDataTable method is used to create a System.Data.DataTable from the columns defined
by the picker dialog control. The GetEntity method is used to convert a DataRow to a
PickerEntity when an item is selected. The interesting work performed by the query control
occurs in the IssueQuery method.

The IssueQuery method takes the search parameters and obtains the search results. The
CreateDataTable method is called to build a DataTable used to pass our data from the query
control to the picker dialog. Once the DataTable is filled with the results of the search the results
are passed to the picker dialog using the PickerDialog.Results property. Finally the number of
matching records is returned to enable paging if necessary.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 74


Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 75
Putting the Picker to Work

Once the editor, picker dialog, and query picker controls are in place we can add it to a
SharePoint page in the same manner as any other control. The first order of business is to add a
<SafeControl /> entry for our assembly to the web.config file and register the control
namespace at the top of our .ASPX page. We can then add the editor control.

City Editor (Single Entry)

City Editor (Multiple Entries)

The final step is to obtain a list of resolved entities when a page action occurs. To get a list of
resolved entities simply call the ResolvedEntities property of the CityEditor instance.

Conclusion

Many people see SharePoint as an extremely effective collaborative solution. As a software


developer you should also notice that the folks at Microsoft have done an excellent job of
making SharePoint a platform for your custom applications. By taking a bit of time to
understand the SharePoint architecture you can take full advantage of the infrastructure
provided. Custom pickers are an effective way to maintain consistency with the SharePoint UI
while reducing the amount of work required to create a custom solution.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 76


Building a SharePoint 2010 Service Application (Audience: .NET
Developers)
By Tony Bierman

Introduction

With each new release of SharePoint, Microsoft has managed to further improve this platform’s
programmability, extensibility, and manageability. Among many other exciting new features
and capabilities, the new 2010 release of SharePoint now provides developers with ASP.NET
AJAX as a first-class tool in our proverbial toolbox. AJAX has been around for some time now,
and it is great to finally see both native and custom SharePoint applications will be enabled with
the same rich, interactive user controls we’ve come to expect from quality browser-based
applications. Yet another exciting technology that ships with SharePoint 2010 is the Service
Application Framework. The Service Application Framework allows developers to create robust
and scalable shared services which can be consumed by multiple SharePoint web applications.

In this article, I’ll show you how to create and provision a SharePoint Service Application. Within
the service application I’ll define a WCF service endpoint which provides auto-completion
services to ASP.NET AJAX-enabled controls. Finally I’ll leverage this WCF service and the
ASP.NET AJAX Toolkit to provide users with a simple Geo-locator page. The Geo-locator will
prompt a user for a city and state, suggesting known values in real-time as the form’s fields are
completed. Once a city and state have been keyed, the user will be shown the specified location
on a satellite map.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 77


Author’s Notes

Admittedly, the use case set forth in this demonstration in somewhat contrived. Using
SharePoint’s Service Application Framework to simply provide AJAX controls with auto-
completion services is really beating a small nail with a big hammer. In most real-world
production scenarios, such trivial functionality could probably be achieved with a simpler site-
level web service. I’ve chosen such a simple use case so as to not distract from the primary
purpose of the article, which is to illustrate how to create and provision the skeleton of a simple
SharePoint Service Application.

The topic of SharePoint Service Applications is broad and technically advanced. Areas such as
scalability, fault-tolerance, external service publishing, security, database provisioning and data
backup are left for another demonstration. That being said, in this article I will get you started
by showing the basics of creating, provisioning and hooking into the Central Administration
management interface for SharePoint Service Applications.

This demonstration is accompanied by a complete Visual Studio solution. The solution is


available for download from the following location:
http://code.google.com/p/autocompletedemo/downloads/list
All code artifacts covered in this narrative are included in the solution. I will walk you through
the process of creating the solution from scratch. As I add each artifact, I will highlight its salient
points, but I will assume you also have the Visual Studio solution open to view complete code
listings. There are a few utility and helper classes in the project which I don’t cover in this
narrative, as I believe these artifacts are self-evident. The Visual Studio solution is meant to be a
starting point for you to create your own SharePoint Service Applications. I hope you will be
able to take the work done here and refactor it to a launching point for your own real-world use
cases.

What You’ll Need

To follow along with this demonstration, I assume you have the following requirements installed
and functioning properly.

Required

 SharePoint 2010 – WSS only will do.


 Visual Studio 2010
 Visual Studio 2010 SharePoint Tools

Optional

 WSS 2010 SDK


 .NET Reflector
 Fiddler

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 78


I also assume that you are an intermediate to advanced SharePoint developer familiar with the
SharePoint object model and the latest ASP.NET, Visual Studio and SharePoint development
tools.

Part One - The Service Application


In SharePoint 2010, the Service Application Framework provides you with the ability to create
hosted, middle-tier services. These shared services can then provide data or processing
resources to other SharePoint features. Native SharePoint applications such as search and Excel
Services are built by using this platform. The platform is now available in SharePoint 2010 for
third parties to also build upon.

Among other things, the Service Application Framework provides:

 Built-in support for building applications using the Windows Communications


Framework (WCF).
 Integration with the standard SharePoint management experience, including
Administration and configuration using SharePoint Central Administration.

Anatomy of a SharePoint Service Application

SPService

A service provides a very narrow range of functionality that usually does not include end-to-end
functions that are valuable in themselves. Services typically run invisibly and have little or no UI.

Every SPService object has an Instances property that holds all the instances of the service that
are running on various servers in the farm. No more than one instance of each service runs on
any one server, but some services have multiple instances, each one running on a different
server. Each instance is represented by an object of a class derived from SPServiceInstance.

SPServiceInstance

SPServiceInstance represents an instance of a service on a server in the farm. A service instance


is independent from, and identical in functionality to, all other server instances of the same
type. As long as one service instance of a given service remains online, the service is fully
functional. Service instances may be in the ‘started’ or ‘stopped’ state. A service instance
provides the host process for service applications.

SPServiceApplication

A service application is hosted by a service instance. Service applications are generally created
by administrators. They provide the service interface, containing the administrator settings.
Service applications may own user data.

SPServiceProxy

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 79


A SPServiceProxy is simply the parent of the SPServiceApplicationProxy. It is the equivalent of a
SPService on the server side, which is the parent of a SPServiceApplication. You can also think of
these parent objects as class factories for the child objects, if that makes more sense to you.

SPServiceApplicationProxy

Service application proxies provide the public (front-end) interface to a service application. They
allow client code to consume remote service applications. Service applications may not be
installed locally and therefore cannot be called directly.

Implementing the Service Application

1. In Visual Studio 2010 I start out by creating a new Empty SharePoint project.

2. When prompted by the SharePoint Customization Wizard, I’m going to target the
Central Administration web, as this is where the service application will be deployed.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 80


Also in the wizard, I’ll select the option to Deploy as a full-trust solution.

3. Next, I add a new class to the project and name it AutoCompletionService.cs. As with all
code artifacts in this demonstration, I’ll cover the highlights of this class, but refer to the
accompanying Visual Studio 2010 sample project for the complete listing. The
AutoCompletionService class inherits the SPIisWebService class and implements the
IServiceAdministration interface. Because this class is a persisted object, it must also be
decorated with the System.Runtime.InteropServices.Guid attribute and assigned a
unique guid.

4. For serialization purposes, the AutoCompletionService class must have a default,


parameter-less constructor. This class also implements a singleton pattern to provide

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 81


the means for acquiring an instance of the local service.

5. I’ll add three more classes to the project. I’m going to name the new classes
AutoCompletionServiceProxy.cs, AutoCompletionServiceApplication.cs and
AutoCompletionServiceApplicationProxy.cs respectively.

6. AutoCompletionServiceApplication inherits from SPIisWebServiceApplication and


implements IFormattable. As a persisted object, the AutoCompletionServiceApplication
class must be decorated with the System.Runtime.InteropServices.Guid attribute and
assigned a unique guid. AutoCompletionServiceApplication overrides the abstract
InstallPath and VirtualPath properties of its parent SPIisWebServiceApplication.
AutoCompletionServiceApplication also overrides the ManageLink virtual property of

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 82


SPServiceApplication.

7. AutoCompletionServiceApplication needs two methods to both provision and


unprovision the service application and its instance. These methods will be called from
the UI when an administrator creates or tears down a service application instance.

8. AutoCompletionServiceProxy inherits from SPIisWebServiceProxy and implements the


IServiceProxyAdministration interface. IServiceProxyAdministration requires the
GetProxyTypes, GetProxyDescription and CreateProxy methods to be implemented.
Also of note, AutoCompletionServiceProxy is decorated with the

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 83


SupportedServiceApplication attribute which tightly couples it to
AutoCompletionServiceApplicationProxy. Refer to the accompanying sample project for
the complete class listing.

9. AutoCompletionServiceApplicationProxy inherits from


SPIisWebServiceApplicationProxy.
10. Add another class titled AutoCompletionServiceInstance.cs to your Visual Studio 2010
project. AutoCompletionServiceInstance inherits from SPIisWebServiceInstance. This
class overrides the DisplayName and TypeName properties. Again, refer to the

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 84


accompanying sample project for the complete class listing.

11. In SharePoint 2010, WCF web services are stored at the path [14 Hive]\WebServices. On
most systems the full path to this location is C:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\14\WebServices. In Visual Studio 2010, I’ll create a
SharePoint Mapped Folder to this location by right-clicking on the AutocompleteDemo
project in Solution Explorer and selecting Add > SharePoint Mapped Folder. Note the 14
hive’s WebServices folder at the bottom of the list.
12. Next, I’m going to expand the newly created WebServices mapped folder and right-click
on the AutocompleteDemo folder below. From the context menu, I select Add > New
Item. In the Add New Item dialog, I select the WCF Service template and name the new

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 85


file YouCompleteMeService.cs.

13. I’m going to move the App.config file that was added automatically to be in the same
folder as YouCompleteMeService.cs. Then I rename App.config to web.config and
delete its contents. I’m going to create my own configuration file. In the web.config file
I’ll turn on aspNetCompatibilityEnabled, define a default endpoint for our WCF service,
and also turn on enableWebScript for AJAX compatibility. Refer to the accompanying

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 86


sample project for the complete web.config listing.

14. For some reason, Visual Studio 2010 doesn’t automatically add a WCF Service Host
declaration file to the SharePoint Project for me. At least in the VS2010 Beta, I’ll have to
add this file manually. To do so, I just add another file to the AutocompleteDemo folder
below WebServices mapped folder in the project. I select a Text file as the file type and
name it YouCompleteMeService.svc. This Service Host file will only contain a few lines
declaring the service and its factory.

15. I’m going to delete the YouCompleteMeService.cs, as I won’t be using it.


16. Now, I’ll add two more classes named AutoCompletionServiceApplicationHostFactory
and AutoCompletionServiceApplicationHost to the root of the project.
AutoCompletionServiceApplicationHostFactory inherits from ServiceHostFactory and

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 87


overrides the CreateServiceHost method.

17. AutoCompletionServiceApplicationHost inherits from System.ServiceModel.ServiceHost


and implements both the IFormattable and IDisposable interfaces.

18. Next, I expand the Features folder of the AutocompleteDemo Visual Studio project and
right-click on Feature1. From the context menu, I click Add Event Receiver. In the newly
created Feature1.EventReceiver.cs class, only the FeatureActivated method is salient to
this application. In the FeatureActivated method, I check to see if an
AutoCompletionService object has ever been created, and if not create it. Only one
local AutoCompletionService will ever be needed. After an AutoCompletionService has

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 88


been created for the first time, SharePoint’s service application management will
become aware of the new service application and allow administrators to create or
manage instances of the Auto Completion Service Application from Central
Administration. I’ll make the admin pages to create and manage our service application
in Part 2.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 89


Part Two – the Service Application’s Admin Interface

The Create and Manage Application Pages

1. In the project, I’ll add a SharePoint Mapped Folder to the *14 Hive+\TEMPLATE\ADMIN

directory.
2. In Solution Explorer, I’m going to expand the newly created ADMIN mapped folder,
right-click the AutocompletionDemo subfolder, and from the context menu Add > New
Item. I select a SharePoint Application Page and name it ServiceCreate.aspx. Then, I

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 90


repeat the process to add one more page named ServiceManage.aspx.

3. The ServiceCreate page will be a popup dialog box, and as such should be modified to
inherit from SharePoint’s ~/_layouts/dialog.master master page. This page will
implement place holders for its master page’s PlaceHolderDialogHeaderPageTitle ,
PlaceHolderDialogDescription and PlaceHolderDialogBodyMainSection content

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 91


sections. Refer to the accompanying sample project for the complete listing.

4. Inside the PlaceHolderDialogBodyMainSection, I add the necessary controls to gather


user input before creating the service application. This page will ask for the service
application’s name, application pool identity, and a check box to set this instance as the

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 92


default.

5. Inside the ServiceCreate page’s code-behind, within the CreateNewServiceApp method


is where the new Auto Completion service application is actually created. All of the
heavy lifting for creating the service application resides with a SPLongOperation. Refer

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 93


to the accompanying sample project for the complete listing.

6. The ServiceManage page is where developer’s are free to add any user configurable
settings for the service application. The Auto Completion service application has no
user configurable options, so this page is largely left blank for the purposes of our demo.
Note that this page’s master page is ~/_admin/admin.master.

7. At this point, the Auto Completion service application can actually be deployed to
SharePoint, and instances of the service application can be provisioned in Central
Administration. Of course, the application doesn’t actually do anything yet, but the core
infrastructure pieces have been defined. To verify this, right-click on the
AutocompleteDemo project in Solution Explorer and select Deploy. The solution will
deployed, and after a few seconds, you should see a “Deploy succeeded” message in the

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 94


bottom left corner of Visual Studio.

8. To verify deployment, I can open SharePoint’s Central Administration site and click on
Manage service applications under the Application Management menu heading.

9. Selecting any item in the list of services will cause the Service Applications ribbon to
appear. I’ll click the New button to see the Auto Complete Service Application list

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 95


there. Now I can go ahead and click it to create a new service application instance.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 96


10. If all is well, I’m presented with a dialog box to create a new Auto Completion service
application instance.

11. Congratulations! If everything works on this next step, most of the hard part is over. I
can go ahead and complete the form by entering an instance name and selecting an
application identity. When finished, I click OK to provision the service application. If the
provisioning succeeded, a pair of listings for the new service application and its proxy
should now be available on the Manage Service Applications Page. I haven’t added any
user configuration options for this demonstration, but clicking the listing’s link to will

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 97


visit the ServiceManage page.

12. One more step to verify the provisioning was successful is to check that the service
application’s virtual application was created in IIS. To do so, I can open Internet
Information Services (IIS) Manager from Administration Tools on the Start menu of the
Windows Server running SharePoint 2010. Next, I’ll expand the Sites node and then
expand the SharePoint Web Services node below that. I right click on one of the virtual

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 98


applications below SharePoint Web Services and select Switch to Content View.

13. I’m looking through the list of virtual applications which have guids for names. Notice
SharePoint’s built-in service applications such as MetadataWebService.svc and
WebAnalyticsService.svc. I’m looking for the virtual application with a guid for a name
that that contains our Service Host file YouCompleteMeService.svc. If everything checks
out, the empty WCF service has been provisioned.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 99


Part Three – The WCF Service Endpoint
1. In this step, I’ll revisit the AutoCompletionServiceApplication class. In order for this class
to provide ASP.NET AJAX auto completion services, I’ll start by decorating it with the
AspNetCompatibilityRequirements attribute.

2. Next, I cause AutoCompletionServiceApplication to implement the


IYouCompleteMeService interface and its required methods. These methods will
provide auto-completion data to the AJAX-enabled input controls I’ll create in the next
step.

3. Note that I’ve created a helper class to handle supplying data to the service methods.
The actual data resides in a simple, albeit lengthy text file. CitiesHelper reads said data
and performs simple Linq queries to filter on the correct city and state names.
CitiesHelper uses a singleton pattern to avoid excessive file I/O and memory usage. In a
real-world production scenario, a more robust SQL database to house this data could
have been provisioned along with the Service Application. However, for the purposes of
this demonstration a simple text file will do fine. Refer to the accompanying project for

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 100


the complete CitiesHelper code listing.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 101


Part Four – The User Application Page
Download the ASP.NET AJAX Control Toolkit

1. The ASP.NET AJAX Control Toolkit is an open-source project built on top of the Microsoft
ASP.NET AJAX framework. It is a joint effort between Microsoft and the ASP.NET AJAX
community that provides a powerful infrastructure to write reusable, customizable and
extensible ASP.NET AJAX extenders and controls, as well as a rich array of controls that
can be used out of the box to create an interactive Web experience. I’m going to use
the toolkit’s AutoCompleteExtender to transform a plain old SharePoint
InputFormTextBox into an AJAX enabled overnight sensation!
a. I’ll create a folder called Dependencies in the same directory as the Visual
Studio solution file. I’ll need to download the ASP.NET AJAX Control Toolkit
binaries from this URL and add the AjaxControlToolkit.dll to the Dependencies
folder.
b. http://www.asp.net/ajax/downloads/

Add a New Project and Test Page

2. In Visual Studio, I’m going to add a new SharePoint Empty Project to the solution and
name it AutoCompletionDemoTest. This time, I’m sure to target a regular SharePoint
content application (not Central Admin as before) from the SharePoint Customization

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 102


Wizard.

3. I add a reference to the downloaded AjaxControlToolkit.dll from the


AutoCompletionDemoTest project.
4. Next, I add a reference to System.Web.Extensions .NET framework assembly from the
AutoCompletionDemoTest project.
5. I also add a project reference to the AutoCompletionDemo project from the
AutoCompletionDemoTest project.
6. The AutoCompletionDemo project is only going to contain one test page. I’m going to
add a new SharePoint Application page to the project and name it appropriately enough
Test.aspx.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 103


7. The main content section of Test.aspx is going to contain a placeholder for the map
along with text input boxes for the user to key-in city and state names.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 104


8. Test.aspx also contains a few Javascript methods to help with retrieving and formatting
the map control based on users’ city and state input.

9. In code-behind file Test.aspx.cs is where I’m going to add control extenders for the
page’s two text input controls. These extenders will handle communicate with the WCF
service’s GetStates and GetCitiesForState web methods to provide suggested auto-

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 105


completion data.

10. To tie everything together, I’ll also add a GetServicesEndpointPath helper method the
test page’s code-behind. This method will go through the Auto Completion Service
Application’s proxy to determine the default service endpoint.

Bringing It All Together

1. From Visual Studio, I’m going to re-deploy the AutocompleteDemo service application
project to Central Admin to ensure the WCF endpoint’s logic is in place.

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 106


2. Next, I’ll deploy the AutocompleteDemoTest test project to a SharePoint content

application.
3. To see the end result, I can browse to Test.aspx in my SharePoint Content Application
by visiting the URL:
a. http://[myserver]/_LAYOUTS/AutoCompletionDemoTest/test.aspx

Copyright 2009 SharePoint Solutions – All Rights Reserved Page | 107

You might also like