Académique Documents
Professionnel Documents
Culture Documents
SharePoint
®
eMagazine
Contents
Thank you! 3
Why would I need a My Site? 4
Controlling the SandBox: A real business necessity 10
PowerShell and SharePoint for beginners 19
FAST Search Server for Power Users 25
Introducing LINQ to SharePoint 35
About DIWUG 41
Fortifying the Pillars of Governance with SharePoint and DocAve 42
Logging and monitoring in SharePoint 2010 46
Building a FAQ with new CQWP functionality in SharePoint 2010 57
Using the refinement panel to get more insight
into your search results 63
The new Enterprise Content Management features
in SharePoint 2010 70
About the authors 86
Colofon
DIWUG SharePoint eMagazine
Nr. 3, September 2010
Publisher:
Stichting Dutch Information Worker User Group (DIWUG)
Third edition, September 2010
Editors:
Marianne van Wanrooij (lead)
marianne@diwug.nl
Mirjam van Olst
mirjam@diwug.nl
2
SharePoint® eMagazine - September 2010
Thank you!
Editor’s note
Thank you (again) for downloading the DIWUG SharePoint eMagazine. And
although this is just the 3rd issue we’re having a special! With over 80 pages of
content for developers, IT-pros and power users we hope you’ll enjoy reading this
magazine!
It seems that SharePoint 2010 is still gaining popularity! Although there was/is
an economic crisis (yes there was one!) there is a high demand for SharePoint
expertise. Maybe this is the reason why more and more companies are looking
into SharePoint to try to get a piece of the action. Although it’s great to have
more people on board in the community, I don’t think that management should
decide over night to “do SharePoint”. When somebody tells me he/she is a Share-
Point Guru my next question is always; “on what part?”. There are only a few
REAL SharePoint Gurus! SharePoint is a complex product with many components
with different kind of business solutions and possibilities. Each part of the Share-
Point pie is an expertise.
In this magazine some of these experts and enthusiasts have written about their
area of expertise. In this issue topics like MySites, PowerShell, FAST search, LINQ to
SharePoint, Content Query Web Part, logging and monitoring, Governance and
Enterprise Content Management shows the variety of components and complexity
of SharePoint 2010. But isn’t that what we like about SharePoint?
I hope you’ll enjoy this issue of the DIWUG SharePoint eMagazine. And don’t
forget to give us your feedback!
Getronics Consulting 9
European SharePoint Best Practices Conference 24
Sponsored article by AvePoint 42
Macaw 56
AvePoint 85
3
SharePoint® eMagazine - September 2010
Internal networking
Nobody can deny the influence of social media in both personal and professional
situations. Nowadays, the mix of personal and professional networks is a given.
Knowledge workers expand their professional network with colleagues worldwide.
The knowledge, gathered through external and internal networking is becoming as
valuable as the one provided by trainings. However, internal networking can play an
even bigger part in professional development than one might think.
Microsoft SharePoint Server 2010 offers employees a personalized platform to expose
their knowledge and expertise to colleagues within company walls. They can store
their personal contact information on the profile page. Anybody can read all about
their colleagues’ profiles, activities and positioning within the organization. This
allows to easily find the perfect sparring partner within their own organization: they
might discover unknown expertise in close colleagues or get to meet new people
with similar interests to their own. The links to profiles are available throughout the
entire farm.
4
SharePoint® eMagazine
The header of the profile contains the worker’s personal and contact information.
This information can be managed by the users themselves. Most fields have a privacy
setting, which allows the employee to choose to limit which people can see it (e.g.
home phone number).
The top zone provides a space to give a brief shout. It can be used to inform people
about current activities, questions or thoughts. Imagine a CEO giving a quick shout
on what his day looks like, a colleague shouting for some assistance with a blocking
issue or a secretary asking everybody to get their timesheets in on time. This can be
compared to a tweet on Twitter or a status update on Facebook or LinkedIn.
Knowledge sharing
Every organization has a massive collection of extremely valuable knowledge.
Wouldn’t it be great if that useful knowledge was shared with colleagues, without
crossing the company’s firewall? Of course, this knowledge should be filtered to
meet your own interests and leave out the information that is not that interesting
or relevant. In the latest version of SharePoint, Microsoft SharePoint Server 2010,
the feature of tagging is introduced. It allows everybody to add specific keywords to
content items such documents, pages and list items across the entire site collections.
In the tab Tags and Notes an overview is given of the user’s activity regarding tags
and notes. The tagging can be done anywhere on site collections and is aggregated
on this personal page. It provides co-workers with an idea of the activity of colleagues
not only in their own office, but in offices all over the world. This brings people closer
together and highly stimulates international cooperation and knowledge sharing.
Can you imagine looking up a person in your company whom you briefly heard about?
Somebody told you he might be interesting to add to your international team. With
Microsoft SharePoint Server 2010 My Sites, his online profile is just a few clicks away.
You can read about his interests, expertise, past projects and current activity, get his
personal contact information and even leave him a note on his note board.
5
SharePoint® eMagazine
Security
The utmost valuable asset of many companies is the in-house knowledge. Although
knowledge sharing is essential within and outside the company’s premises, you would
like to limit the knowledge interchange of company critical information to the outside
world. Of course, externally managed platforms such as LinkedIn or Twitter offer a
much larger audience. This hands your workers a huge knowledge exchange platform
which can be extremely valuable in some scenarios. However, it might also form a
disclosure risk of company-confidential information. An internal, closed environment
like Microsoft SharePoint Server 2010 offers a secure place to store and exchange
sensitive information, minimizing the risk of leaks to the outside world.
6
SharePoint® eMagazine
7
SharePoint® eMagazine
Documents area are visible to the user only, while Shared Documents can be shared
with all or just selected system users.
Because of this centralized way of working, all storage and backup is managed by the
farm administrators.. This has a positive effect on both the cost-of-control and the
complexity of these essential mechanisms, compared to a decentralized approach.
The Microsoft SharePoint Server 2010 Central Administration website has a built-in
interface for quick and easy backup schedules and restore scenarios.
Conclusion
Online social media are the newest way to share knowledge within the organization
and beyond. One way to make sure the organization’s confidential information
remains within company walls is to provide these capabilities inside those same
company boundaries. Microsoft SharePoint Server 2010 offers this functionality in
a secure and closed environment. It helps knowledge workers to stay up-to-date on
their knowledge area by exchanging valuable information with their own co-workers,
within the own organization.
The out-of-the-box mechanisms of document management, access control, backup-
restore and Business Connectivity Services can lower the cost-of-control and
complexity of the storage and enhance transparency as well as ease-of-use for both
administrators and end-users.
Microsoft SharePoint Server 2010 My Site is a complete, secure and mature
environment for knowledge sharing, internal networking and information exposure.
The added value of these processes is higher productivity, openness and a higher
team work spirit. Every company with a strong knowledge sharing and collaboration
need should invest in Microsoft SharePoint 2010 Server My Sites and start working
more effectively.
Start discovering your in-house knowledge today!
8
CONNECT
SHARE
DISCOVER
getronicsconsulting.com
Getronics Consulting
SharePoint® eMagazine - September 2010
For a complete review of the SharePoint Sandbox, its use and application, examine the article
“Sandboxed Solutions in SharePoint 2010” written by Mirjam van Olst in the
January 2010 SharePoint eMagazine issue (http://www.sdn.nl/LinkClick.aspx?fileticket
=nCffQTC9R7g%3d&tabid=139&mid=668&forcedownload=true).
Microsoft has decided that a sandboxed solution is the default type of solution for SharePoint.
To enforce this, the default SharePoint solution type of new Visual Studio projects is always
sandboxed (except if it is impossible to implement the solution in the sandbox).
However, as both choices (sandbox and farm implementation) are available, it’s up to you to
decide which one is the best solution for your specific situation. Having said that, Microsoft
expects a large explosion of commercial sandboxed solutions (these are not yet visible as
SharePoint 2010 is only a few months old).
As you can see, deciding on the use of sandboxed solutions is a governance issue, not
a technical one. As the number of users increases, the importance of governance also
increases. And if the number of users increases, sandboxed solutions become more
and more important.
10
SharePoint® eMagazine
If the company decides to shut down the Sandbox, there are different options. Each
has advantages and disadvantages:
SharePoint Online is a bit of a special case. Sandboxed solutions were developed with
SharePoint Online in mind. In a SharePoint Online environment sandboxed solutions
will be the only way to deploy customizations to your sites.
11
SharePoint® eMagazine
[Guid(“D84E464F-5056-4082-A75F-D10C0786DB89”)]
class ValidatorStrongName : SPSolutionValidator
Listing 1: ValidatorStrongName.
SPSolutionValidator is a class in the Microsoft.SharePoint.UserCode NameSpace, thus
a directive “using” to this namespace must be in place. A using directive to Microsoft.
SharePoint.Administration is also necessary as well. The base source code for the class
would be:
public ValidatorStrongName() { }
SharePoint 2010 installs by default one empty validator called “Default solution
validator”; empty means that the “Valid” properties in both methods are hard coded
to be “true”. The Validator can be found in the Microsoft.SharePoint.UserCode
namespace under the class SPDefaultSolutionValidator. The class can be decompiled
to observe its code structure, similar to the code shown in the last paragraph.
In the example, we would like to validate that the SharePoint Solution naming respects
the established enterprise rules of a hypothetical company indicating that any solution
name must follow the structure “MyCompany.[Department].[SolutionName]”.
To ensure this business rule, we can use a helper routine to split the name into its
components and check for the first one:
12
SharePoint® eMagazine
return blnReturn;
}
properties.Valid = SolutionNameIsCorrect(properties.Name);
}
return blnReturn;
}
13
SharePoint® eMagazine
ReadOnlyCollection<byte> readOnlyAssembly =
new ReadOnlyCollection<byte>(assembly.OpenBinary());
byte[] byteArrayAssembly = new byte[readOnlyAssembly.Count];
readOnlyAssembly.CopyTo(byteArrayAssembly, 0);
Listing 6: ConvertAssembly.
The SignatureIsCorrect helper routine uses a string constant “PublicKeyBlob” defined
at the beginning of the class to make the validation. For simplicity, the public key value
has been hard coded, but it can be saved using any dynamic method (for example in
the web.config file). “Using” directives to the following name spaces are necessary:
using System.Collections;
using System.Reflection;
using System.Security.Policy;
using System.Collections.ObjectModel;
$bytes = $null;
$assembly = “pathTo\StrongNamedAssembly.dll”;
$bytes = [System.Reflection.Assembly]::LoadFrom($assembly).GetName().
GetPublicKey();
$key = “”;
for($i=0; $i -lt $bytes.Length; $i++)
{
$key += “{0:x}” -f $bytes[$i];
}
$key;
if (myPublicKeyTokenS.Equals(PublicKeyToken))
blnReturn = true;
return blnReturn;
}
14
SharePoint® eMagazine
The “GetPublicKeyToken” method returns the token as a byte array; using a LINQ
expression, it is converted to a hex string and compared to the fast coded value of the
original signature file. One “using” directive to System.Linq is necessary.
To show in the SharePoint User Interface that the validation has been rejected, the
class SPSolutionValidationProperties has two properties: one for an error message
(“ValidationErrorMessage”) and one to redirect to an aspx page (“Validation-
ErrorUrl”). To make use of this infrastructure, create an aspx page in the validator
project (in Visual Studio 2010, go to Project - Add New Item - Application Page) giving
it a distinctive name (“SolutionValidationPage.aspx” in the example). In the Place-
HolderMain, add some text indicating that the solution cannot be installed, and in
the PlaceHolderPageTitle, add a title for the page itself:
Listing 12: The final source code of ValidateSolution and Validate Assembly.
Finally, the validator must be activated when the project is installed in SharePoint.
This can be done by adding a feature and its event receiver. Add the feature to the
project, change its name to “ValidatorKey” and add the event receiver. Uncomment
the methods FeatureActivated and FeatureDeactivating. Add a “using” directive to
Microsoft.SharePoint.Administration.
15
SharePoint® eMagazine
In the method FeatureActivated, add the validator class to the collection of SPUser-
CodeService.Local.SolutionValidators validators. In the FeatureDeactivating method,
remove the class from the collection using its GUID (defined for the decoration of the
validator class):
$spusercodeservice =
[Microsoft.SharePoint.Administration.SPUserCodeService]::Local;
$spusercodeservice.SolutionValidators;
16
SharePoint® eMagazine
$spusercodeservice =
[Microsoft.SharePoint.Administration.SPUserCodeService]::Local
$spusercodeservice.ResourceMeasures
$SPUserCodeService =
[Microsoft.SharePoint.Administration.SPUserCodeService]::Local
$oneFactor = $SPUserCodeService.ResourceMeasures[“UnresponsiveprocessCount”]
$oneFactor.AbsoluteLimit = 3
$oneFactor.Update
Listing 17: Reading the metrics with a console application in Visual Studio 2010.
And change them:
17
SharePoint® eMagazine
SPResourceMeasure myUnresponsibleProcess =
resourceMeasureColl[FactorName];
myUnresponsibleProcess.AbsoluteLimit = FactorNewValue;
myUnresponsibleProcess.Update();
}
Conclusions
The SharePoint sandboxed approach is an important feature that can give a plethora
of opportunities for allowing users to install their own software. But freedom can
create also chaos. Sandbox validators can reduce the level of anarchy and maintain the
control over the software installed without the necessity off shut down the sandbox.
Click on the relevant illustration to download the full Acrobat-pdf version or the
eReader-pdf version. For additional information about DIWUG please go to page 41.
18
SharePoint® eMagazine - September 2010
Hello PowerShell
PowerShell has been around for quite some time now, it started somewhere in the
summer of 2005 with the public beta named Monad, and it has evolved to a version
2.0 since August 2009. And since it’s rolled out with Windows7 and Windows Server
2008 R2 most of us probably have seen it in some form. So since PowerShell is a
commandline interpreter it looks like the old command tool (cmd.exe).
Since SharePoint 2010 is x64 based, only use the PowerShell x64
PowerShell allows you to work with the commandline shown in Figure 1, that way
it works almost the same way as stsadm. However scripting is made a bit easier, you
now have a nice Integrated Scripting Environment, named the PowerShell ISE. If you
don’t have the PowerShell ISE yet you can easily enable it with PowerShell.
19
SharePoint® eMagazine
$int = 1
$int + $int + $int
20
SharePoint® eMagazine
[int]$newint = 1
[int]$newint = “Some text” #results in error
$arraya = 1..5
[array]$arrayb = 5..10
[array]$arrayb = 1,3,5,7,9
$arraya
$arrayb
$arrayc
# Quoting rules
$a = ‘PowerShell World’
write-output ‘Hello $a’ # no variable expansion
“hello $a” #variable expansion
“Length of ‘$a’ is $($a.Length)”
$multiline = @’
a
multiline
string
‘@
So in order to run either scripts you created yourself, or scripts you downloaded from
the Internet, you have to use the Set-ExecutionPolicy and set it to Unrestricted (see
Listing 5 for an example, where you can also can see that retrieving parameters and
21
SharePoint® eMagazine
passing them to another script is pretty easy). If you want to understand exactly how
the ExecutionPolicy works, and how it prevents bad things to happen, there are
several good MSDN articles on the security model of PowerShell.
#retrieve ExecutionPolicy
Get-ExecutionPolicy
Set-ExecutionPolicy Unrestricted
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$mysite=new-object Microsoft.SharePoint.SPSite(“http://portal.sp2010.dev”)
$myweb = $mysite.Rootweb
$myweb | GM
22
SharePoint® eMagazine
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
$mysite=new-object Microsoft.SharePoint.SPSite(“http://portal.sp2010.dev”)
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
Get-Command –PSSnapin “Microsoft.SharePoint.PowerShell” | select name, definition
$CrawlContent = Get-SPEnterpriseSearchServiceApplication|
Get-SPEnterpriseSearchCrawlContentSource
23
EUROPEAN BEST PRACTICES 11TH–13TH APRIL 2011, LONDON, UK
SHAREPOINT CONFERENCE
EUROPEAN
SHAREPOINT
™
BEST PRACTICES
CONFERENCE
LONDON 2011
QUEEN ELIZABETH II CONFERENCE
CENTRE, LONDON 11TH-13TH APRIL, 2011
The European SharePoint Best Practices Conference Learn practical and productive SharePoint practices
returns to London in 2011, hosted once more by from the industry’s leading authorities. Event speakers
Combined Knowledge. include:
• Microsoft MVPs
Best Practices is about doing things the right way:
• Microsoft Product Team Members
finding the smartest ideas, activities and techniques
• Industry Experts
around. With 5 tracks dedicated to all types of
audience from IT Pros, Developers, Information
Workers, Project Managers and Business Event hosted by
Managers/Information Directors, this is the largest
SharePoint conference to come to the UK and has
something for everyone.
The Best Practice Conference is all about real
WIN AN XBOX! Everybody who
world experience designing and using SharePoint, registers will be entered into a
and tailored tracks will appeal to IT Pros, free weekly draw to win an XBox
Developers and Designers, Information Workers, 360. See the web site for details!
Architects and Taxonomists, Project Managers
and Information Officers.
#bpc11
Key features
Let’s start by taking a look at an out-of-the-box search center using FAST Search for
SharePoint.
Conversational Capabilities
Deep Results Refinement
The column on the left in figure 1 contains the refinement panel. It allows users to
filter search results on metadata. Refiners are available in SharePoint Search as well,
but FAST Search for SharePoint offers the concept of deep refiners. This feature adds
counts to each filter, depicting the total number of search results available with that
filter applied. Also, the displayed refiners are based on all results in the result set, not
just the first 100 search results, which is default behavior in SharePoint Search.
Refiners can be added to the refinement panel for any managed property.
25
SharePoint® eMagazine
Managed Properties
You might be unfamiliar with the term “Managed Property”, so let me explain what
it means. When content is crawled and indexed, the crawler marks various aspects
of the content as a property and puts this information in a so called Property Store
(which is actually one of the search databases). These aspects can be metadata added
by the author of the content, but it can also be information that is “gathered” during
the crawl process, for instance the language of the content, or the file type (Word,
PowerPoint, etc.). In SharePoint, these properties are called “Crawled Properties”.
Crawled properties cannot be used by the query engine directly. For this, a crawled
property first needs to be mapped to a Managed Property. When a property is
“managed”, it can be used by the query engine. This means the property can be used
in search queries; it can also be used in the Advanced Search screen, in the Sort By
dropdown, in the Refinement Panel, etc.
Property extraction
FAST Search for SharePoint adds a unique feature to the process of gathering
metadata, called metadata/property extraction. While processing the content,
FAST Search for SharePoint is able to extract metadata from content by matching
terms in a dictionary to terms used in the content. Out of the box, FAST Search
for SharePoint can identify company names, person names and geographic names/
locations in documents. The extracted properties can be used to improve the search
experience, for example by adding refiners based on these properties.
Result count
Right above the search results is the total number of search results. Obviously,
this information is also available in SharePoint Search. A very small but important
difference however, is that in FAST Search for SharePoint it says “1-10 of 61 results”,
where in SharePoint Search it would say “1-10 of about 61 results”. This difference is
explained by the fact that FAST Search for SharePoint is much better at knowing the
exact number of results for a given search request. The number shown by SharePoint
Search is only an educated guess.
26
SharePoint® eMagazine
Let’s see how a managed property is configured so it can be used for sorting:
In Central Administration, under “Manage Service Applications”, click on the FAST
Search Service Application link (in this case “FASTQuery”). From this page, navigate
to “FAST Search Administration”, which is available in the top left navigation. Then
go to “Managed Properties”.
The list on this page shows all the available Managed Properties. In this example,
we’ll make sure the Content Type property is available for sorting. Find the Content
Type property and click it. Now check the “Sort property” (figure 3) checkbox and
click the OK button.
Similar Results
Each search result contains a link that says “Similar Results”. By clicking on this link,
the user performs a new search request to include documents that are similar to that
specific result. This feature is unique in FAST Search for SharePoint.
Result Collapsing
If multiple copies of the same document exist in a crawled source, the indexed copies
will have the same checksum. When performing a search request, FAST Search for
27
SharePoint® eMagazine
SharePoint will collapse these documents as one document in the result set, avoiding
that the same document appears multiple times in the search results.
If a search result is collapsed, it contains a link that says “Duplicates (n)”, where n is
the number of duplicates available in the index of that piece of content. Clicking on
this link performs a new search request that returns all duplicates as individual search
results. This feature is unique to FAST Search for SharePoint.
Contextual Search
Another unique feature that’s only available in FAST Search for SharePoint is the
concept of “contextual search”. This feature allows you to configure the search center
to react differently to specific groups of users, personalizing the search experience.
Configuring so called “user contexts” is the key point here. By defining user contexts
you’re basically defining audiences for your search center. These user contexts can
then be used to target Best Bets, Visual Best Bets, document promotions, document
demotions, site promotions and site demotions.
User Contexts
Let’s see how contextual search can be configured. We’ll start by adding a user context
to our search center. Note that the entire configuration regarding contextual search is
done at site collection level.
28
SharePoint® eMagazine
Go to the site settings page of the search center. If this isn’t the root web of the
site collection, make sure you go to the Top Level Site Settings. Then locate the
Site Collection Administration pane and click the link that says “FAST Search user
context“. Please be aware that the FAST links in the site collection settings will always
be available, even if FAST is not installed or configured in your environment. If you
click a FAST link when FAST is not installed, you will get an error message.
This page shows all User Contexts that have been configured previously. Add a new
User Context by clicking the “Add User Context” link in figure 7.
29
SharePoint® eMagazine
Best Bets, Visual Best Bets, Document Promotions and Document Demotions
Before we start configuring (Visual) Best Bets and Document Promotions/Demotions,
let’s see what the default search results look like when I’m searching for “content
management” as a logged on user that meets the criteria of our previously created
User Context:
30
SharePoint® eMagazine
Nothing special to see here, since we haven’t configured anything for our User
Context yet. To configure (Visual) Best Bets or Document Promotions/Demotions, we
first need to add one or more keyword terms. When a query includes one of these
keyword terms (or one of its configured synonyms), Best Bets are displayed promi-
nently on the search results page. With document promotions and demotions, admin-
istrators can move specific search results for a keyword to the top or the bottom of
the search results list.
Let’s create a keyword term for “content management” and add a Visual Best Bet.
We’ll also try to promote the “Gear Promo” document that’s currently on the bottom
of the page.
Again, go to the site settings page of the root web of the search center site collection.
This time click the FAST Search keywords link in the Site Collection Administration
pane. This page shows all keywords that have been configured previously. Click “Add
Keyword” to add a new keyword:
$formPath = “pathtoform”
Test-SPInfoPathFormTemplate -Path $formPath
Install-SPInfoPathFormTemplate -Path $formPath
31
SharePoint® eMagazine
Let´s create a Keyword for the keyword phrase “content management”. Note that
we can add synonyms for our keyword. When users search for the keyword, results
from all synonyms will also be displayed in the search result. There’s a distinction
between one-way synonyms and two-way synonyms. When users search for a
one-way synonym, only results are returned for this synonym. If a user searches for a
two-way synonym, results are returned for this synonym in addition to results for the
keyword and all other synonyms. In our example we’ll just add a keyword without
adding synonyms:
32
SharePoint® eMagazine
Finally, we’ll add a Document Promotion for the “Gear Promo” document. This process
is quite similar to adding a Visual Best Bet, but in this case the URL points to the “Gear
Promo” document:
33
SharePoint® eMagazine
Conclusion
It’s clear that FAST Search Server 2010 for SharePoint adds quite some value to the
search experience by providing enhancements and new capabilities to the enterprise
search features of SharePoint Server 2010. Visual search capabilities like thumbnails,
previews and best bets provide an efficient way for information workers to interact
with search results. On the other hand, conversational search capabilities like result
sorting, deep refinement, similar results and collapsing duplicate results provide ways
for information workers to interact with and refine their search results, so that they
can quickly find the information they require. Finally, by providing contextual search
capabilities, FAST Search for SharePoint adds the ability to personalize the search
experience in a powerful way.
34
SharePoint® eMagazine - September 2010
Introduction
Prior to SharePoint 2010 there were already numerous programmatic ways to get
content out of SharePoint. There was the Object Model, SP Web Services and of
course CAML queries. We now have an additional option: LINQ to SharePoint. While
some may wonder why we need yet another way, LINQ seems to have truly taken off
in many other .NET development circles and so perhaps we SharePoint folks should
consider it.
What is LINQ to SharePoint then? Loosely stated, LINQ is a query language that
you can write inline in your code. The “to SharePoint” part means that the query
is executed against the SharePoint content database: in other words against your
SharePoint lists, content types and list items. LINQ to SharePoint is actually a
latecomer to the game as other LINQ providers such as LINQ to SQL and LINQ to
XML have been around for some time. If you have used LINQ syntax with any of
these, you will not be surprised that the LINQ to SharePoint syntax is the same. This
has the benefit that you no longer have to know CAML to query SharePoint. LINQ
operates on strongly typed objects, so you don’t have to worry about typos (like in
CAML) and you get IntelliSense in Visual Studio. Everything is no longer a SPListItem.
[Microsoft.SharePoint.Linq.ContentTypeAttribute(Name=”Announcement”,
Id=”0x0104”)]
public partial class Announcement : Item
{
private string _body;
private System.Nullable<System.DateTime> _expires;
...
public Announcement() {
this.OnCreated();
}
[Microsoft.SharePoint.Linq.ColumnAttribute(Name=”Body”, Storage=”_body”,
FieldType=”Note”)]
public string Body {
get { ... }
set { ... }
}
}
[Microsoft.SharePoint.Linq.ColumnAttribute(Name=”Expires”,
Storage=”_expires”, FieldType=”DateTime”)]
public System.Nullable<System.DateTime> Expires {
get { ... }
set { ... }
}
}
}
35
SharePoint® eMagazine
There is no magic way for the LINQ to SharePoint provider to know what content we
have put into SharePoint, or to know how we want that content to be represented in
code. The link (no pun intended) that lets us code against strongly typed representations
of our content comes in the form of Entity Classes. These classes map SharePoint content
to an object oriented structure. Let’s see an example to make things clearer.
Listing 1 shows the entity class for an out of box SharePoint Announcement. Note that
most of the implementation has been removed to conserve space. We will not drill
into all the details of this class, but let’s get an idea of what is going on here. The first
thing to notice is that we are looking at a strongly typed class called Announcement,
which inherits from another class named Item. This hierarchy should sound familiar to
you if you have worked with SharePoint before as the Announcement content type
inherits from the Item content type. Next, notice that there are two public properties:
Body and Expires. If we look at Figure 1, we notice that these are two columns that
are part of the Announcement content type but are NOT inherited from the Item
content type.
36
SharePoint® eMagazine
Listing 3 shows the SPMetal command, where we have added two parameters.
First we specify that the namespace for the generated classes should be TestProject
andsecond we specify a parameters XML file. The XML file contents are shown in
Listing 4.
37
SharePoint® eMagazine
Querying data
Up to this point we have been looking at all the pieces required to get LINQ to Share-
Point to work properly. Now we get to finally use LINQ queries against SharePoint
and pull some data out. Let’s start with a basic query and say we need to get all the
announcements that have expired or are expiring today. Also, we are only interested in
their ID and Title fields. Back in the CAML query days this would not necessarily been a
‘basic’ query. Listing 8 has the code to perform this query, let’s go through it.
38
SharePoint® eMagazine
tdc.SubmitChanges();
39
SharePoint® eMagazine
So what if you want to see the CAML that LINQ to SharePoint is generating? It is
quite easy to do, actually. The DataContext (derived or not) has a Log property that
accepts a TextWriter object. The DataContext will then write the queries it generates
to the TextWriter. My favorite means of testing this is using a literal in a web part
and writing the content of the log to the literal using a StringWriter. This can be seen
in Listing 11. Note that due to the deferred nature of LINQ queries, the query only
executes if it is used. Therefore simply inserting a query into the example will not
generate any Log output. Code that uses the query also needs to be inserted into this
listing, such as a foreach loop enumerating the results.
<View>
<Query>
<Where>
<And>
<BeginsWith>
<FieldRef Name=”ContentTypeId” />
<Value Type=”ContentTypeId”>0x0100</Value>
</BeginsWith>
<Lt>
<FieldRef Name=”AnnouncementExpires” IncludeTimeValue=”TRUE” />
<Value Type=”Lookup”>2010-07-08T00:00:00Z</Value>
</Lt>
</And>
</Where>
</Query>
<ViewFields>
<FieldRef Name=”Announcement” LookupId=”TRUE” />
<FieldRef Name=”Title” />
<FieldRef Name=”AnnouncementExpires” />
</ViewFields>
<ProjectedFields>
<Field Name=”AnnouncementExpires” Type=”Lookup” List=”Announcement”
ShowField=”Expires” />
</ProjectedFields>
<Joins>
<Join Type=”LEFT” ListAlias=”Announcement”>
<!--List Name: MyAnnouncements-->
<Eq>
<FieldRef Name=”Announcement” RefType=”ID” />
<FieldRef List=”Announcement” Name=”ID” />
</Eq>
</Join>
</Joins>
<RowLimit Paged=”TRUE”>2147483647</RowLimit>
</View>
Limitations
LINQ to SharePoint is not perfect. It offers a lot, but is has a few shortcomings. First,
LINQ to SharePoint does not work for anonymous users. This is bad news to those who
build public facing web sites since there is likely a large part of your content that will
need to be accessible to anonymous users. Second, LINQ to SharePoint doesn’t work
across site collections. You cannot query one site collection from another. Both these
issues can be solved with a workaround that involves manipulating the HttpContext,
but it feels like a hack and the performance implications are unknown. Third, LINQ
40
SharePoint® eMagazine
to SharePoint does not support all the queries that the LINQ syntax allows. See the
reading list for more details.
Conclusion
LINQ to SharePoint brings the power of LINQ queries into the SharePoint arena. While
CAML queries work great, they are not great to work with. LINQ abstracts CAML
and lets developers query the content database in a much easier way. By providing
strongly typed objects for all CRUD operations LINQ to SharePoint results in more
consistent, cleaner and more simple code.
Reading List
SPMetal Parameters file schema:
http://msdn.microsoft.com/en-us/library/ee535058.aspx
Writing data to SharePoint, including conflict resolution:
http://msdn.microsoft.com/en-us/library/ee538246.aspx
Unsupported LINQ Queries and Two-stage Queries:
http://msdn.microsoft.com/en-us/library/ee536585(office.14).aspx
About DIWUG
DIWUG is a platform for people that are interested in information worker solutions. Several
times a year, DIWUG organizes events where members can meet, share knowledge and see
interesting presentations in an informal setting.
Contact information:
Marianne van Wanrooij; marianne @diwug.nl
Mirjam van Olst; mirjam@diwug.nl
Mart Muller; mart@diwug.nl
http://www.diwug.nl
41
SharePoint® eMagazine - September 2010
So what can we elucidate from these general definitions? To begin our discussion,
let’s draw one important line in the sand: While IT plays an instrumental role in
the performance of “good governance”, governance is not simply a software- or
hardware-driven initiative. Let’s be clear: Governance is neither a technology nor a
tool. First and foremost, governance is a business decision.
This business decision must be made – and led – by the C-Suite. Executive-level
management must ensure that it is stewarding and fully supporting the initiative
in order to ensure it is truly effective. This executive-level sponsorship must cover
the execution of the governance initiative, establishing the procedures necessary to
implement governance, and purchasing the tools necessary to aid in that execution.
Notice that “purchasing tools to aid in execution” is last on the list. A clear plan must
be established first. Part of that plan must include getting all of the key organization
employees to the table to hammer out a successful governance strategy. This roster
can include the C-level executives, financial stakeholders, IT leaders, business division
leaders, information architects/taxonomists, compliance officers, development
leaders, knowledge workers, and trainers.
What’s at risk? Exposure to legal and compliance-related issues, much in the same
vein as Enron and other companies that fell victim to litigation leading to their
ultimate demise. When these companies did fall, and numerous compliance regula-
tions – including Sarbanes Oxley – came out, many organizations reactively purchased
technology platforms such as Microsoft SharePoint to centralize and standardize their
businesses without proactively giving thought to proper governance. The end-result
was often a collaboration environment and digital asset repository burdened with
sprawl, decreased security, excessive administration costs, depressed user adoption,
and, yes, susceptibility to compliance-related issues – exactly what organizations were
trying to avoid. This problem still rears its head today – according to research from the
Association for Information and Image Management (AIIM), less than 50 percent of
SharePoint implementations were subject to a formal business case, and only half of
those required a financial justification. Consequently, most companies did not have a
management plan as to which of SharePoint’s features were to be used, and where.
42
SharePoint® eMagazine
43
SharePoint® eMagazine
The ability to discover and modify SharePoint securities is similarly limited, as native
SharePoint tools do not allow administrators to discover the deployment-wide
access/modification rights for a particular end-user or group without manually
searching each element within the entire deployment. Furthermore, in more complex
environments with complex inheritance, administrators cannot discover and modify
securities changes for an end-user or group without accessing the settings interface
of each SharePoint element or object for which that user has prescribed permissions.
There is really no native way to search, view, or modify all elements and objects for
which a specific end-user or group has permissions, leading to inefficient use of an
administrator’s time, and a poorly governed information security strategy.
SharePoint’s native capabilities with regard to the protection, access, and lifecycle
management of content and data are also limited. SharePoint cannot natively
backup and restore data and content at the item-level with full fidelity, nor can it
ensure total farm backup of all SharePoint components, including the GAC, IIS, the
SharePoint Hive, and other front-end customizations. There is no native functionality
enabling organizations to optimize the performance of their SharePoint deployment
via business-rule aware archiving, or any way to ensure all geographically distributed
end-users accessing offline or satellite SharePoint farms have access to the same,
up-to-date information as those accessing the central, or main farm.
Additionally, out-of-the-box reporting, auditing, and archiving features for the sake
of meeting compliance obligations are not robust enough for organizations crafting
a comprehensive governance strategy. SharePoint cannot perform full-data capture
archive snapshots – including securities, metadata, and audit trail – retain them in
an immutable form, or maintain them outside of SharePoint’s SQL storage. Targeted
audit retrieval or reporting by user, object, and activity is also lacking in out-of-the-
box SharePoint deployments. Executing automated data pruning – based on globally
defined retention policies – is not possible natively, nor is tracking and reporting
upon all SharePoint activities from the object, user, or event perspective.
SharePoint provides the foundation for governance, but additional technical tools
are required – in conjunction with appropriate procedural protocols – to ensure truly
effective and efficient management of site and information architecture, securities
and policies, operational procedures, and compliance adherence.
44
SharePoint® eMagazine
With the DocAve Software Platform, organizations will have the tools required to
successfully execute a robust governance strategy efficiently, meet their evolving
compliance objectives, and ensure optimal performance of their SharePoint platform.
45
SharePoint® eMagazine - September 2010
Diagnostic Logging
You will use diagnostic logging to keep an eye on what is going on your server.
Diagnostic logging is used to collect event and trace information. If you used Share-
Point 2007 you are probably familiar with SharePoint’s diagnostic logging. However,
diagnostic logging has been greatly improved in SharePoint 2010.
Information gathered through diagnostic logging is stored in the Windows event logs
and in the so called ULS logs. By default these logs are stored in the C:\Program Files\
Common Files\Microsoft Shared\Web Server Extensions\14\LOGS\ folder. The ULS log
files have a .log extension. All data that is written to the ULS logs is also written to the
logging database so it can be used for reporting purposes later on.
You can configure the diagnostic logging settings by going into Central Administration
=> Monitoring => Configure diagnostic logging.
46
SharePoint® eMagazine
47
SharePoint® eMagazine
48
SharePoint® eMagazine
If you have ever tried to open a .usage file you know that these files weren’t meant
to be a nice bedtime story. The data in them is binary. There are two log collection
timer jobs that are both needed to help you make the collected data useful. The first
one is the Microsoft SharePoint Foundation Usage Data Import timer job and this one
is used for collecting the data from the .usage files from each SharePoint server in the
farm and storing the information in the logging database. By default this job will run
every 30 minutes, but you can adjust this if you want to.
49
SharePoint® eMagazine
The second timer job is the Microsoft SharePoint Foundation Usage Data Processing
job. This job is used for processing the data, so that it can be used to generate reports.
By default this job will only run once a day.
By checking the Enable health data collection checkbox and setting up a schedule
for the health data timer jobs you can enable health data collection. Health data is
not logged to the files system of the SharePoint servers. It is logged directly to the
logging database. We will talk about this database in great detail later.
If you click on the Health Logging Schedule link you will see a list of timer jobs that
are related to health logging. Many of them are enabled. Most of the diagnostic
data provider timer jobs however are disabled by default. There is a reason for this.
If you enable these timer jobs, and more specifically the Diagnostic Data Provider:
Performance Counters - Database Servers timer job and the Diagnostic Data Provider:
Performance Counters – Web Front Ends timer job they will extend the schema of
your logging database and they will start logging like crazy. So much so that the
amount of data stored in the logging database will get into the tens or hundreds
of gigabytes, if not terabytes. Writing all this data to the logging database will also
batter the hard drive of your SQL server so much that the logging database might
require its own SQL server.
Logging Database
At the bottom of the usage and health data collection page you can select a database
server and database name for the logging database. Be aware that this database is
sometimes called the usage database. Don’t let this confuse you, it’s the same thing.
All the information collected by the diagnostic providers and by the usage and health
timer jobs is eventually stored in the logging database. This means that this database
can get very busy and very big. If you are serious about using the health data collection
features, it can get so busy that Microsoft recommends giving this database its own
SQL server instance. The logging DB should never be stored on the same physical disks
as the search or content databases, because that will result in massive disk contention
for all three databases. If you plan to use the health data collection features you need
to carefully design your storage layer. It should be obvious from the above statements
that you have to pay close attention to what information you are logging and whether
you actually need that information. If you don’t need the information don’t collect it
and don’t consume unnecessary resources.
By default the logging database stores 14 days’ worth of data. By running a Power-
Shell script this can be extended to up to 31 days. Be aware that every time you
change the retention policy all tables in the logging database are emptied and you
will lose the data you collected up till that point.
The schema of the logging database is documented. This means that you can write
data to the logging database and you can read, query and build reports directly from
it. To make sure you don’t cause locks on the database it will be better to make a
snapshot of the logging database and use that for reading and querying the data.
The bottom line however is that the logging database is the first SharePoint database
that you are allowed to touch. It is even supported to change the database schema
by adding tables or stored procedures. Don’t modify the schema of any of the default
objects in the database as that could problems when SharePoint tries to write data
to it.
Here is an example of a query that you could run against the logging database.
This query will get you yesterday’s slowest pages for the web application with web
application id d75c0a2e-2e15-4d1a-b300-7889fa86133f on the mysharepointserver-
name SharePoint server.
This query is just one example; you can generate an almost unlimited amount of
reports from the data in the logging database.
50
SharePoint® eMagazine
51
SharePoint® eMagazine
To gather data the health analyzer timer jobs will get information from the servers
in the farm and from the logging database. This data will be used by the rules to
determine whether the farm is healthy and stable.
When a rule fails, the status is written to the Health Analyzer Reports list in Central
Administration and to the Windows event log. Also a message will be displayed on
the homepage of the Central Administration telling the administrator that the health
analyzer has detected an issue. The colour of the bar tells you how serious of an issue
the health analyzer has found.
On the page in Central Administration displaying the Health Analyzer Reports list
you can click an alert to view more information about the problem and see steps to
resolve the problem. You can also change the settings for the rule that raised the
alert.
The Health Analyzer Reports list is just another SharePoint list, with the same options
other SharePoint lists have. This means you can for instance create your own views on
the list and put alerts on it so you get a warning when anything changes.
52
SharePoint® eMagazine
Be aware that there will always be messages in the list of problems and solutions.
They do no harm. Two examples of these are:
n The “Missing server side dependencies” that is there by default and that is
looking for a dll that is apparently missing on the server, even if you installed
everything the way it should be installed.
n The “The server farm account should not be used for other services” will popup
if you are running the user profile service. This will by default use the farm
account. There is no way around this, you can’t change it, or your user profile
synchronization won’t work. You shouldn’t use the farm account for any of the
other services. That would be a bad practice. This rule will be changed in a later
hotfix, so it won’t fire for the user profile service anymore. For now you can just
ignore the message.
Don’t make it your life’s mission to get rid of every message in the Health Analyzer
list, but do keep track of messages in there so you will be able to spot potential
problems and solve them before they cause real damage to your farm.
Web Analytics
You could argue that the web analytics features in SharePoint 2010 aren’t really part
of the logging and monitoring features. However they do use a lot of the logging and
monitoring features, which is why I will cover them in this article anyway.
SharePoint 2010 has its own web analytics service application that can be created
and managed from the managed service applications page in Central Administration.
When creating the service application you will also create the staging and the reporting
databases that are used by the web analytics service application to store and query the
usage data.
The “Web Analytics Data Processing” timer job will (just like the usage data
collection timer jobs) use the .usage files to collect information about the farm
from the SharePoint servers. This makes the web analytics features the only log data
collection features that don’t use the logging database.
It also means that the web analytics features need the .usage files in order to be
able to function. Because of this usage data collection must be enabled for the web
analytics service to work. If you create the web analytics service application it will
automatically enable the usage data collection for you. Be aware that if you manually
disable the usage data collection timer jobs or delete the usage data collection service
application that your web analytics will stop working.
53
SharePoint® eMagazine
The data in the staging database is retained for 30 days and moved into the reporting
database for longer term retention. The retention time for data in the reporting
database ranges from 1 to 25 months and can be selected when creating the web
analytics service application. The meat of the web analytics features is the ”Web
Analytics Web Service”, which contains most of the logic needed for the web analytics
features to work.
Reports
We spend quite a lot of time on how and where SharePoint collects all its logging and
monitoring data. Of course this isn’t any good if you can’t view and create reports
that use all the collected data.
The diagnostic logging information is surfaced in the ULS logs and in the Windows
Event Logs. This information will mainly be used to track down the cause of problems
on your environment and not necessarily to generate reports on.
The usage and health data information that is stored in the logging database is
surfaced in reports on the view administrative reports and the view health reports
pages.
The messages generated by the health analyzer are available in the Review problems
and solutions list and in the Windows Event Viewer.
Web analytics reports are shown on the View Web Analytics reports page. The web
analytics reports show data collected per web application. From the site settings
pages the Site Collection Web Analytics reports and the Site Web Analytics reports
can be opened. These reports show similar information that will be relevant to the
current site or site collection. The site and site collection reports can be viewed by
site owners and site collection administrators, enabling them to get some insights
into the behavior of users on their sites without them needing access to Central
Administration.
Because a lot of data is stored in the logging database and it is possible to write your
own queries against this database you can easily create your own custom reports
using Excel, SQL Reporting Services or third party reporting tools. This means that
you can create some really fancy reports about the data logged into the logging
database by just using pivot tables and slicer in Excel. A lot of reporting that can be
done without using SQL Server Reporting Services.
54
SharePoint® eMagazine
Conclusion
In this article we have looked at the different logging and monitoring features in
SharePoint 2010. Hopefully by now you will have an understanding of what feature
you should use for what purpose, where the different features store their information
and where you can see the logged data being surfaced.
Table 1 provides a very short overview of the features, the places where they log and
the different reporting options.
55
Wat doe jij volgende maand?
Jij bouwt het wereldwijde intranet voor een grote multinational, waar de meer dan
25.000 gebruikers dagelijks met veel plezier mee werken. Je opent de poorten naar
kritische ERP, BI en HR systemen en integreert die met de modernste Document
Management en Social Networking applicaties.
Jij bent namelijk een specialist die wel raad weet met SharePoint 2010, Nintex Workflow
en WSF. Iemand die altijd op zoek is naar nieuwe kennis en als eerste met de technologie
van morgen wil werken, maar ook iemand die geniet van het succes dat de klant vandaag
boekt met jouw innovatieve oplossingen.
Jij bent ondernemend en deelt graag je visie en kennis met je omgeving, zowel fysiek als
online, en werkt samen met designers, architecten, developers en consultants aan de
beste oplossingen voor je klant. Je weet hoe je werk en privé vlekkeloos kunt combineren
en onafhankelijk van tijd en plaats de optimale bijdrage levert aan je team.
Bezoek voor meer informatie over deze en andere vacatures onze website www.echtleukwerk.nl of neem contact
op met onze afdeling Recruitment via 020-8510510 of recruitment@macaw.nl.
Macaw
SharePoint® eMagazine - September 2010
57
SharePoint® eMagazine
58
SharePoint® eMagazine
Additional filters
SharePoint 2010 introduces two new filters in the CQWP which are very useful. Note
that there is a question mark next to the heading in the web part – this has a good
summary which always helps me out when my memory of the correct context fails
me.
59
SharePoint® eMagazine
60
SharePoint® eMagazine
You can edit the CQWP further, for example to limit the number of results returned,
change the sort order, etc.
61
SharePoint® eMagazine
Make a link in the web part for each of your categories – each link needs to point to
the current page.
CQWP
The next step is to place a CQWP in the left column. This will be picking up the correct
FAQ pages for us.
The values for this CQWP are the same as for the CQWP when showing related
information. Instead of filtering with the PageFieldValue, we’ll be filtering with the
PageQueryString, to grab that variable out of the URL:
Figure 8: Example of the CQWP filtering according to the Summary Links web part.
When you link to the page, make sure to include the query string with the category
that you want to show by default, e.g. http://www.test.com/pages/default.
aspx?cat=General info.
Conclusions
In this article, we worked through putting together all the steps for a FAQ. This could
very easily be reused for any kind of information that needs to be filtered and shown
on a page, such as a news archive or a product catalogue. The taxonomy and managed
metadata features offer many new options within SharePoint 2010 besides the one
that has been handled – I expect many interesting solutions to pop up as more users
work with them.
62
SharePoint® eMagazine - September 2010
“Searching or filtering”
In the last couple of years, good search functionality has become one of the most
important requirements when building a new corporate portal. More and more
people are becoming familiar with using a search engine. Since the relevance of the
search results has been improved greatly, users rely more on the search functionality
as the way to get to the organizational information.
63
SharePoint® eMagazine
One of the big differences between searching for information on the internet (using
Google or Bing) and searching for information on your corporate portal is that the
information on your corporate portal is in a (semi-)controlled environment. This
makes it possible to enrich information with metadata when it is created or added.
The “structured” properties attached to the “unstructured” information such as
documents or webpages make it possible to search for information not only based on
keywords, but also by filtering the results based on unique properties. Searching for
information in a filtered set of search results gives much better results. For example,
finding that specific application form for attending a conference is much easier if you
perform a query for “conference application form” only within all application forms
instead of performing that query throughout the whole SharePoint portal.
Refining the number of results based on properties is used on almost all major
commerce sites. Figure 1 shows a screenshot of a Dutch commerce site that gives
visitors the opportunity to refine the number of found products based on different
categories.
MOSS 2007 didn’t provide any out of the box functionality for achieving this. The
CodePlex tool “Faceted Search” (http://facetedsearch.codeplex.com/) made it possible
to do a refinement on your search result page. However, it also had some downsides
such as the requirement to install the Microsoft Enterprise Library software; it was
also not possible to refine your search based on date ranges.
64
SharePoint® eMagazine
65
SharePoint® eMagazine
Property Description
Filter Category Definition This XML string configures the categories for which you can refine the
search results. I will go deeper into this property later on.
Number of categories to display The number of categories which are shown on the screen. Make
sure this number is similar or higher than the number of categories
you’ve configured in the “Filter Category definition” property or your
categories will not be shown.
Number of characters to display If the values in the refinement categories are very long, the values will
be truncated to the number of characters set in this property.
Use Default Configuration This checkbox resets the values of the web part properties to its original
values. By default it is checked. Make sure you uncheck this checkbox so
that your settings apply!
Data view properties – XSL editor This property allows you to configure the look and feel of the refinement
panel. Like the core results web part, this is done by editing some XSLT
code.
Table 2: Most important properties for configuring the refinement panel web part.
66
SharePoint® eMagazine
NumberOfFiltersToDisplay=”4”
MaxNumberOfFilters=”20”
SortBy=”Frequency”
SortByForMoreFilters=”Name”
SortDirection=”Descending”
SortDirectionForMoreFilters=”Ascending”
ShowMoreLink=”True”
MappedProperty=”Vestiging”
MoreLinkText=”show more”
LessLinkText=”show fewer” />
</FilterCategories>
<CustomFilter CustomValue=”Documents”>
<OriginalValue>docx</OriginalValue>
<OriginalValue>pdf</OriginalValue>
</CustomFilter>
<CustomFilter CustomValue=”Image”>
<OriginalValue>png</OriginalValue>
<OriginalValue>jpg</OriginalValue>
</CustomFilter>
67
SharePoint® eMagazine
Range mapping is used for date or numeric ranges. The following example shows a
custom filter that shows how many results are changed within the last week.
68
SharePoint® eMagazine
Conclusion
The new refinement panel web parts in SharePoint 2010 give the SharePoint search
functionality a big boost. Using a search engine only by querying full text keywords
isn’t enough anymore. Applying metadata to information and tagging content by
the author on add/upload or by the users in the form of social tagging gives the
ability to see information from different anchors and is essential for web parts like
the refinement panels to enrich the user experience of your SharePoint 2010 portal.
Links
http://www.cmswire.com/cms/document-management/sharepoint-2010-using-
taxonomy-metadata-to-improve-search-discovery-007425.php
http://msdn.microsoft.com/en-us/library/ff625183(v=office.14).aspx
69
SharePoint® eMagazine - September 2010
The following ECM features are a huge improvement on the 2007 version:
However, we did run into some limitations while trying to preserve metadata when
documents were moved, while using outgoing email and while trying to do bulk
updates of metadata from the datasheet view.
In this article we will focus on how to setup the Content Type Publishing Hub and
the Managed Metadata Service Application, as well as how to overcome some of
the limitations by bending the SharePoint import / export framework and using the
dialog framework. We assume that the reader has some experience running the
SharePoint 2010 Management Shell (PowerShell) and also has experience in the
SharePoint Object Model and C#.
n You want to use a Content Type Publishing Hub to centrally manage all of your
content types to subscribed web applications
n You want to offer taxonomy lists as a new site column called Managed Metadata
column
After the SharePoint 2010 installation, you can automatically provision the service
applications via the wizard. In this article, we will show you how to provision your
own managed metadata service using PowerShell.
We choose to use PowerShell as our the weapon of choice for administrating
SharePoint. In order to be successful, make sure that you run the SharePoint 2010
shell as an administrator, that you have farm rights and have spshelladmin rights
(otherwise you cannot execute PowerShell command against SharePoint 2010). The
cmdlet get-spshelladmin will show the privileged accounts.
Make sure that you created a managed metadata service application and that the
managed metadata service instance is started (you can find this under Service on
Server in the Central Administration web site). You can check whether the service
is started by using the SharePoint PowerShell cmdlet get-spserviceinstance. If the
status is disabled then you will need to start the managed metadata service using the
cmdlet start-spserviceinstance -Identity [id of the service instance as shown below].
70
SharePoint® eMagazine
<SharePointInstaller>
<Services>
<MetaDataService Name=”DMS Metadata Service”
DatabaseServer=”mydbserver”
DatabaseName=”SharePoint_Metadata”
FailoverDatabaseServer=””
HubUri=”http://foobar.com/sites/contenttypehub”>
<ApplicationPool Name=”SharePoint Hosted Services”
Account=”CORP\SP_WorkerProcess” />
<Proxy Name=”DMS Metadata Service Proxy” Partitioned=”false”>
<ProxyGroup Name=”Default” />
</Proxy>
</MetaDataService>
</Services>
<SharePointInstaller>
function Start-MetaDataService([string]$settingsFile) {
try {
#Initialize settings
[xml]$config = Get-Content $settingsFile
$svcConfig = $config.SharePointInstaller.Services.MetaDataService
#Managed Account
$ManagedAccount = Get-SPManagedAccount | select -First 1
if ($ManagedAccount -eq $NULL)
{ throw “No Managed Accounts” }
$farm = Get-SPFarm
$buildversion = $farm.BuildVersion
#App Pool
$ApplicationPool = Get-SPServiceApplicationPool`
$svcConfig.ApplicationPool.Name -ea SilentlyContinue
if($ApplicationPool -eq $null)
{
71
SharePoint® eMagazine
$ApplicationPool = New-SPServiceApplicationPool`
$svcConfig.ApplicationPool.Name -account $ManagedAccount
if (-not $?)
{ throw “Failed to create an application pool” }
}
Figure 2: The managed metadata service application with two term sets.
72
SharePoint® eMagazine
Figure 3: The properties of the managed metadata service application show the url of
the Content Type Publishing Hub.
Figure 4: The properties of the managed metadata service proxy show the settings for
the connection to the Content Type Publishing Hub.
73
SharePoint® eMagazine
Once you have activated the feature, you can create the content types that you want
to publish in the Content Type Publishing Hub. Just create the content types as you
would normally do either through the UI or by using a SharePoint feature defining
the content type and activate this on the site collection. You will also need to activate
the document ID feature in all site collections that are subscribed to the hub if content
types in the hub use document IDs.
In the example below, we publish the content types in the Content Type Publishing
Hub. We assume that all published content types are part of the content type group
called DMS Group.
When finished creating the content types, they need to be published so the subscribed
web application can consume the content types from the hub. Using the following
PowerShell script we can publish all content types in the Content Type Publishing
Hub site collection that are part of the DMS Group. First of all we need to extend the
settings.xml to provide some more settings:
74
SharePoint® eMagazine
function Subscribe-ContentTypes([string]$settingsFile)
{
[xml]$settings = Get-Content $settingsFile
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
[System.Reflection.Assembly]::LoadWithPartialName
(“Microsoft.SharePoint.Administration”)
[System.Reflection.Assembly]::LoadWithPartialName
(“Microsoft.SharePoint.Taxonomy”)
75
SharePoint® eMagazine
Woonplaats,Gemeente,Provincie,Latitude,Longitude
‘s-Graveland,Wijdemeren,Noord-Holland,,
‘s-Gravendeel,Binnenmaas,Zuid-Holland,,
‘s-Gravenmoer,Dongen,Noord-Brabant,51.66666670,4.80000000
‘s-Gravenpolder,Borsele,Zeeland,51.45000000,3.90000000
Listing 6: The resulting csv after using the macro, ready for import into the Managed
Metadata Service Application.
76
SharePoint® eMagazine
Extend the settings file as follows and also make sure that the path to the csv file is
set correctly in the settings file.
<Metadata>
<TermStore Name=”DMS Metadata Service Proxy”>
<Group Name=”Netherlands”>
<TermSet Name=”Dutch places” File=”C:\temp\cities.csv”></TermSet>
</Group>
</TermStore>
</Metadata>
Listing 7: Extending the settings file to declare settings for the taxonomy.
Now you can use the following PowerShell function to create the term set in the
managed metadata service application:
function Create-Taxonomy([string]$settingsFile)
{
[System.Reflection.Assembly]::LoadWithPartialName
(“Microsoft.SharePoint.Taxonomy”)
[xml]$config = Get-Content $settingsFile
$Thesite = new-object Microsoft.SharePoint.SPSite
($config.SharePointInstaller.ServiceSettings.CentralAdministration.Url)
Write-Host “Site url: $($Thesite.Url)”
$session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession
($Thesite, $true)
$session.TermStores | ForEach-Object {
Write-Host “Termstore: $($_.Name)”
if ($_.Name -eq
$config.SharePointInstaller.ServiceSettings.Metadata.TermStore.Name)
{
$termstore = $_
}
}
Write-Host “Selected termstore: $($termstore.Name)”
$im = $termstore.GetImportManager()
$group.TermSets | ForEach-Object {
Write-Host “Termset: $($_.Name)”
if ($_.Name -eq $_.TermSet.Name) {
$termset = $_
}
}
77
SharePoint® eMagazine
$termset = $im.ImportTermSet
($group, $importFile, [ref] $allTermsAdded, [ref] $importErrorMessage)
}
}
78
SharePoint® eMagazine
The first thing we did was checking out whether the out of the box functionality
could help us to achieve our goals. We checked out the following options:
n SPFile.MoveTo
n Send Document to Repository (SharePoint Designer workflow activity)
n Export and import
SPFile.MoveTo, this method only allows us to move our files between libraries within
the same site collection. Another minor detail about this method is that when a
document is moved it counts as a modification, therefore changing the modified
property timestamp.
Send Document to Repository, this will only allow us to send files to a record center or
to a site collection that has the Content Organizer feature enabled. Unfortunately, in
our case the documents ended up in the content organizer’s drop off folder instead
of in the intended directory. This approach also modifies the document’s timestamp.
Export and import, this will allow us to keep our versions and doesn’t modify the
timestamp, but it only allows us to move files to the same library within another site
collection.
After finding out that none of the out of the box features were suitable, we decided
to modify the export and import process. Before starting the export process it can
be configured using the SPExportSettings. One of the properties of the SPExportSet-
tings object is the FileCompression property. Setting the FileCompression property
to false will export your item and its setting files into separate files. Two of the files
created during the export are RootObjectMap.xml and Manifest.xml. We did a lot of
investigating and testing in order to figure out how we could edit the files so that
the item would be imported into our destination library.
79
SharePoint® eMagazine
We created an extension method for the SPListItem class that will first call our export
method using the predefined export settings.
Listing 10: Replacing the source url with the destination url.
80
SharePoint® eMagazine
We only change the library urls within these files. It is not necessary to change the
site collection urls within these files because export and import does this for you.
The import only requires us to configure the UpdateVersions to SPUpdateVersions.
Overwrite. The reason for setting the Overwrite will be explained below.
The import code is displayed in listing 11.
importSettings.BaseFileName = Path.GetFileName(fileToImport);
importSettings.FileLocation = Path.GetDirectoryName(fileToImport);
importSettings.SiteUrl = siteURL;
importSettings.RetainObjectIdentity = false;
importSettings.IncludeSecurity = SPIncludeSecurity.All;
importSettings.UpdateVersions = SPUpdateVersions.Overwrite;
importSettings.UserInfoDateTime =
SPImportUserInfoDateTimeOption.ImportAll;
importSettings.FileCompression = false;
81
SharePoint® eMagazine
82
SharePoint® eMagazine
The Command parameter of the Button element refers to the EmailFiles command
we defined in the CommandUIHandlers section. The JavaScript in this function is
responsible for opening our modal dialog page and it supplies a callback function
that handles the returned SP.UI.DialogResult by displaying it in the notification bar
that was introduced with SharePoint 2010. Enabling/disabling our button depending
on the number of documents the user has selected is also done in this JavaScript. You
could extend this and hide it if outgoing email isn’t configured on the server, like
Microsoft did with the Alert Me button.
<CommandUIHandlers>
<CommandUIHandler Command=”EmailFiles” CommandAction =”javascript:
function emailFilesCallback(dialogResult, returnValue)
{
if (dialogResult == SP.UI.DialogResult.OK)
{
SP.UI.Notify.addNotification(returnValue);
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK);
}
else if (dialogResult == SP.UI.DialogResult.cancel)
{
SP.UI.Notify.addNotification(returnValue);
SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.cancel);
}
}
83
SharePoint® eMagazine
The sender data is set to the current user’s email address and we use the SMTP server
specified in the farms outbound mail settings. We retrieve these settings via the
OutboundMailServiceInstance property of the current SPWebApplication object.
84
SharePoint® eMagazine
the selected items to a layouts page, we enable the user to choose a client from
our BCS list and set the metadata for multiple documents in a single action. As you
can probably imagine, this increases productivity in a mailroom where hundreds of
documents pass through the inbox every single day.
Conclusion
In this article we have shown you how to setup the Managed Metadata Service
Application, how to get the Content Type Hub up and running and how to create a
taxonomy in the Managed Metadata Service Application. We have also shown you
some limitations of SharePoint 2010 and how you can deal with them. We believe
that the ECM features of SharePoint 2010 combined with the existing features such as
Import /Export and the power of the Dialog Framework provide great opportunities
in the ECM market for SharePoint developers.
AvePoint
85
SharePoint® eMagazine - September 2010
86
SharePoint® eMagazine
Tycho Bizot worked for Logica CMG in the first years of his career
andworked on several SharePoint 2007 projects. He joined Sparked
in 2010 and is now working on several SharePoint 2010 and 2007
projects.
Web: http://www.sparked.nl or http://tycho.bizot.nl
Email: tycho.bizot@sparked.nl or Tycho@bizot.nl
Dolf den Ouden has always been passionate about IT. After high
school, he did two Technical Information studies resulting in his
bachelor degree. Dolf started his own company, developing several
websites and web applications. After finishing his degree in 2006
he started working at Logica and specialized in.NET and SharePoint
development. In 2009 he joined Sparked.
Web: http://www.dolfdenouden.nl or http://www.italkcode.net
Email: Dolf.den.ouden@sparked.nl
87