Integrate Beyond Compare with Visual Studio Source Control

Like everyone else, I have my own preferences to configure my development environment. One of the tools I’m using is Beyond Compare. Besides the main features of the tool, I like the integration with Visual Studio and Visual Studio Team Foundation (TFS) the best and it’s really simple! But I always forget the command and arguments to use. This is why I’m writing this post.

Configure Beyond Compare as version history compare tool for Visual Studio 2010:

  1. Open Visual Studio
  2. Open Tools » Options…
  3. In the tree on the left go to Source Control » Visual Studio Team Foundation
  4. Click Configure User Tools…
  5. Click Add…
  6. Set the following fields
    1. Extention: *
    2. Operation: Compare
    3. Command: C:\Program Files (x86)\Beyond Compare 3\BCompare.exe
    4. Arguments: %1 %2 –readonly /lefttitle=%6 /righttitle=%7

The arguments allow you to control the behavior of Beyond Compare. Labels to use:

  • %1: Original file
  • %2: Modified file
  • %5: Diff command-line options
  • %6: Original file label
  • %7: Modified file label

Export WSP solution packages

When WSP packages are added to a SharePoint farm they are stored in the config database. This is done to ensure new servers added to the farm can be synchronized with the specific farm configuration including WSP solution package deployment.

Because solution packages are stored in the config database, it’s possible to download/export the WSP package with PowerShell.

Get-SPSolution | ForEach-Object { $_.SolutionFile.SaveAs($_.SolutionFile.Name) }

The WSP packages are stored in the current directory.

Approaches to migrating your service applications

While working my way through TechNet documentation, I came across this very interesting table! It describes supported methods for service application migration.

The forth column shows the support for read-only database. You can find more information on read-only databases here: Run a farm that uses read-only databases (SharePoint Server 2010) [http://technet.microsoft.com/en-us/library/dd793608.aspx].

Service application

Database

Supported approach

Supports read-only

Notes

Access Services

None

not available

not available

 

Application Discovery and Load Balancing

None

not available

not available

Application Registry Service

Application Registry Service

Recreate

No

Business Data Connectivity

Business Data Connectivity

· Database attach

· Recreate

Excel Services

none

not available

not available

Microsoft SharePoint Foundation Subscription Settings

Subscription

Database attach

Managed Metadata Service

Managed Metadata Service

· Database attach

· Recreate

PerformancePoint Services

PerformancePoint Services

Recreate

PowerPoint Service

None

not available

not available

Project Server service application

· Draft

· Published

· Archive

· Reporting

Database attach

No

· Requires synchronization between the databases

· Need to configure time stamps or log marking

For more information, see Database-attach full upgrade to Project Server 2010

SharePoint Server Search

· Search Administration

· Crawl

· Property

· Recreate

· SharePoint backup and restore

No

· The index partitions are copied to the new farm and then restored on the new database server.

· The search topology is exported and then restored to the new server.

Secure Store

Secure Store

· Database attach

· Recreate

The pass phrase for the new database must be identical to the source database.

Security Token Service

Recreate

State Service

State

Recreate

No

Usage and Health Data Collection

Logging

Recreate

No

User Profile

· Profile

· Synchronization

· Social tagging

· Database attach

· Recreate

Profile requires the restoration of an encrypted FIM key

Visio Graphics Service

None

not available

not available

Web Analytics Service

· Staging

· Reporting

· Database attach

· Recreate

Word Automation Service

Word Automation Services

Recreate

not available

Word Viewing Service

None

not available

not available

 

Display exceptions in application pages

SharePoint OOTB displays user friendly an error page to end users. As a developer we want the .NET error page displaying detailed information about the exception thrown. By updating the web.config file with the following parameters the detailed information is displayed.

<configuration> <SharePoint> <SafeMode CallStack="true" /> </SharePoint> <system.web> <customErrors mode="Off" /> <compilation debug="true" /> </system.web> </configuration>

By only changing the web.config file in the web application root, located in “C:\inetpub\wwwRoot\wss\<webapp>”, will not display detailed information in application pages (a.k.a. layouts pages).

There is more than one web.config file! Check your SharePoint Root folder.

Update the configuration show above in the “…\14\TEMPLATE\LAYOUTS\web.config” file and this will result in a .NET error page for application pages.

Build your own custom administration

Managing application specific configuration is mostly done within an application page (aka layouts page). Navigating to these pages is done via custom actions, which adds links to for example the Site Settings page. The challenge starts when the number of application pages grows. Do you keep adding them to the Site Settings page? Do you show them on all Site Settings pages in the web application of every web?

What you need is a centralized administration, like the Central Administration, controlling your application configuration. The Central Administration in SharePoint has two sorts of pages. The homepage (default.aspx) providing an overview and pages like Application Management showing a collection of links related to Application Management.

CentralAdministration_Homepage CentralAdministration_ApplicationManagement

It’s easy to build your own custom administration site. The image below shows my own administration site. Do you see the resemblance?

ApplicationAdministration_Homepage ApplicationAdministration_Security

Creating these pages is pretty straightforward when using the FeatureLinkSections class together with “LinkSectionLevel1.ascx” and “LinkSectionLevel2.ascx” controls. This web control handles the rendering of the links based on enabled features in the current context. The links are provisioned by custom actions as part of a (enabled) feature.

<SharePoint:FeatureLinkSections Runat="server" Id="SettingLinksV4" CellPadding="4" CellSpacing="4" Location="Contoso.SharePoint.AdminPage" LinkSectionControl="LinkSectionLevel1.ascx" />

The Location attribute is an unique identifier indicating the location where links are provisioned. The location is used in the custom action XML (shown below) to point to the location in the FeatureLinkSections control.

<!-- Admin Page - Security --> <CustomActionGroup Id="ContosoSecurity" Title="Contoso Security" Location="Contoso.SharePoint.AdminPage" Sequence="10" Description="" ImageUrl="/_layouts/images/ SiteSettings_UsersAndPermissions_48x48.png" /> <CustomAction Id="ContosoAdmins" GroupId="ContosoSecurity" Location="Contoso.SharePoint.AdminPage" Rights="EnumeratePermissions,BrowseUserInfo" Sequence="10" Title="Contoso Administrators" Description="..."> <UrlAction Url="_layouts/people.aspx" /> </CustomAction>

The FeatureLinkSections control uses two views controlled by the LinkSectionControl attribute.

LinkSectionLinks1.ascx

Shows a 48×48 icon for the group and links are placed below each other.

LinkSectionLinks1

LinkSectionLinks2.ascx

Shows a 32×32 icon for the group and links are delimited by the “|” character. LinkSectionLinks2

 

Visual Studio solution

I included the Visual Studio project containing the following components:

  • AdminPages_Web feature: Web scoped feature with event receiver updating the welcome page and quicklaunch. The feature contains the following components:
    • AdminPage module
    • AdminPageActions custom actions
    • PBWebTemplate element
    • Event receiver
  • AdminSite_Site feature: Site collection scoped feature containing the web template for creating the web. The feature contains the following components:
    • AdminWebTemplate web template
  • AdminPageActions custom actions: All custom actions containing all links displayed in the central adminstration.
  • AdminPages module: Provisions the adminpage.aspx and security.aspx pages in the web root folder.
  • AdminWebTemplate web template: Contains the web template for creating the web.
  • PBWebTemplate element: Property bag element with unique web template id

DownloadYou can download the WSP package and source code at http://sp2010admin.codeplex.com/.

Word text generator for Lorem Ipsum

Regularly I need Word documents with example text. Word has a example text generator feature which creates text like “Lorem ipsum dolor sit amet, consectetuer …” or “On the Insert tab, the galleries include items that are designed …” or “The quick brown fox jumps over the lazy dog. The quick brown fox …”.

Simply start Word and type =lorem(3,10) and press Enter

Word 2010, lorem ipsum function

This results in:

Word 2010, lorem ipsum result

There are some options you can use:

  • =lorem(p, l) where p is the number of paragraphs and l the number of lines per paragraph.
  • =rand(p,l) provides the same functionality but using different text “On the Insert tab, the galleries include items that are designed …
  • =rand.old(p,l) also provides the same functionality using different text “The quick brown fox jumps over the lazy dog. The quick brown fox …

Maybe you already knew, maybe not. I was looking for the “The quick brown fox jumps over the lazy dog. The quick brown fox …” text and thought lets share!

Out of the box Field and ContentType IDs

SharePoint keeps amazing me, even after working more than 6 years with the product. The product is this big that’s it is almost impossible to know all. This is one of those things. I simply did see it before.

When working on a “Yet Another SharePoint Gem” as Robin Meure called it. I stumbled on the SPBuiltInFieldId class and SPBuiltInContentTypeId class. When retrieving information like the CreatedBy field (also known as Author) it is very useful. Also when checking whether a item is based on a out-of-the-box (OOTB) content type. See exaples below.

Update: in addition to both SharePoint 2010 Foundation classes SharePoint Server has ContentTypeId class and FieldId class. Both are part of the Microsoft.SharePoint.Publishing namespace. Thanks to Jeffrey Schmitz (@DJeffa).

Here an example for the extension of the SPListItem class to retrieve the Author:

public static class SPListItemExtentions { /// <summary> /// Gets the author of a list item. /// </summary> /// <param name="item">Extended class.</param> /// <returns>Returns the author of the list item.</returns> public static SPUser GetAuthor(this SPListItem item) { string user = item[SPBuiltInFieldId.Author].ToString(); int userId = Convert.ToInt16(user.Split(';')[0]); return item.Web.AllUsers.GetByID(userId); } }

Another example for checking the base content type:

SPListItem item = list.GetItemById(1); SPListItem topic = item; // If item isn't the dicussion topic, get topic! if (!item.ContentType.Id.IsChildOf(SPBuiltInContentTypeId.Discussion)) topic = GetTopicItem(item);

Upgrading MOSS2007 to SharePoint 2010 results in navigation error

Having issues with navigation after an upgrade from MOSS2007 to SharePoint 2010 using the publishing template? We did! After an upgrade the navigation returned errors instead of menu items. We encountered these issues when the Dutch language pack was installed, because the Pages library has been translated/renamed to “Paginas”.

SharePoint Upgrade navigation errors Dutch Language Pack

Microsoft has provided a solution described in KB 2484317. The root cause of the issue is described as:

With Microsoft Office SharePoint Server 2007 we stored new Publishing Pages in a library called Pages. In SharePoint 2010 it has been translated to Paginas as the default for Dutch. The navigation code assumes that any changes from the default are noted in a specific property, which is not the case for upgraded Dutch sites that have been created with the 2007 default name.

The solution to this problem is pretty easy, a simple PowerShell script will restore your navigation.

$site = Get-SPSite("http://WebApplicationURL") foreach ($web in $site.AllWebs) { Write-Output("web:" + $web.ServerRelativeUrl); $pageslistid = $web.AllProperties["__PagesListId"] if ([String]::IsNullOrEmpty($pageslistid)) { Write-Output($web.ServerRelativeUrl +" doesn't have a pages list id set - skipping"); } else { $pageslistguid = new-object System.Guid($pageslistid) $pageslist = $web.Lists[$pageslistguid] $pagesurl = $pageslist.RootFolder.Url $pb = $web.Properties; $pb.Add("__PagesListName", $pagesurl); $pb.Update(); Write-Output($web.ServerRelativeUrl +" set pages list to " + $pagesurl); } }

PowerShell script for retrieving AD user attributes based on display name

Populating more than 1.000 people picker values based on users display name can be quite challenging when doing it manually. PowerShell to the rescue!

This script reads a TXT-file with 1 users’ display name per line. Per user it searches the local directory and outputs the displayName and sAMAccountName in a semicolon separated line (easy for Excel extraction).

PowerShell script:

function ConvertUser($user) { $search = New-Object DirectoryServices.DirectorySearcher([ADSI]“”) $search.filter = “(&(objectClass=user)(displayName=$user))” $results = $search.Findall() foreach($result in $results){ $userEntry = $result.GetDirectoryEntry() Write-Output('' + $userEntry.displayName + ';' + $userEntry.sAMAccountName) } } function ConvertUsers { process{ foreach($user In $_){ ConvertUser($user) } } } Get-Content “.\Users.txt” | ConvertUsers

TXT-file with users (filename: “Users.txt”):

Aaron Painter Adam Barr Alan Brewer Alan Steiner

Make a TXT-file with users display name (see example below). Then copy, paste and run the script above should do the trick.

image

Follow

Get every new post delivered to your Inbox.