Links for 70-573 training

12. February 2011

Now and then I do training with the subject SharePoint 2010 development – and very often I talk about links for blog posts, tools, etc.. I find interesting. This is the collection, which of course will be extended whenever I find more interesting links.

Creating a virtual machine

Tools and extensions

Certification specific blog-posts

Optimizing your code

Fields, Content Types, Lists & Content Types – blog posts

Web Parts

Client Object Model

Search

Dates and the FullTextSqlQuery

Enterprise Content Management

Application Lifecycle Management

Administrative API

Videos and screencasts

The best error description

8. September 2010

Just got this beautiful baby of an error message from a FullTextSqlQuery in my Sharepoint 2010 development computer– awesome and very helpful errorJ

 

Why can’t I get a Document ID….??

6. September 2010

Got a scenario with SharePoint 2010, where I needed an Enterprise Wiki for an intranet-site and then as sub-sites for this a bunch of team-sites. One of the requests was to get the Document ID up and running, so my attempt was to go to site collection features and activate the Document ID Service feature….that should do….at least that was what I thought.

However, I found after playing a couple of hours on my dev-machine, it seems that if you need both document ID’s and the publishing feature, you have to activate the document ID feature before the publishing feature. In this case I had nearly no custizations made to the Pages-library apart from a couple of web parts added to the default-page.

After deactivating the site collection publishing feature (and destroying my pages-library), activating the document ID service feature, they both were working.

Versioning and upgrading your features with SharePoint 2010 Application Lifecycle Management (ALM)

30. April 2010

One of the nice features of SharePoint 2010 is the possibility you actually have to version your features and update your features in a more sensible way than the previous version did. In SharePoint 2007 the feature had a version property, which basically allowed developers to keep track of the versions themselves – SharePoint did in other words never use the property for anything.

Times have changed – in SharePoint 2010 the application Lifecycle Management actually allows you to upgrade your features which in the simplest form lets you change the name of previous uploaded files, add an additional element-file or the thing I have seen cause the most WAUW-effect during the Ignite-trainings I have held in Denmark – adding fields to an already deployed content type in your farm. In this walk-through our goal is to accomplish the last scenario – so let’s start up. I have a newly created team-site with no customizations accomplished on the url http://intranet

Creating the basic content type feature

So let’s start up by creating a basic feature with a content type with a single note-field – just to have something to play around with

  1. Open Visual Studio 2010 and create a new Empty SharePoint Project – my project is named TheUpgradeableCT – and the name will be important later, so if you chose another name, some of the walkthrough won’t be completely copy/paste. Deploy it as a farm solution against http://intranet or whatever site collection you wish as a debug-site – again – I will use the url later
  2. Right-click the project and add a Content Type Item to the project – name it The Upgradeable Content Type and chose Document as the base content type when the wizard appear and click Finish.
  3. Paste the following into the elements-file created in your content type node – this will create a basic document content type

<?xml version=1.0encoding=utf-8?>
<Elements xmlns=http://schemas.microsoft.com/sharepoint/>

<!– Parent ContentType: Document (0×0101) –>
<ContentType ID=0x0101009214903b71c048a0ba7a7ec3dff0d9dd
Name=TheUpgradeableCT
Group=A feature upgrade attempt
Description=The upgradeable content type
Version=0>
<FieldRefs>
<FieldRef ID={67BC24C5-C864-4CE5-9855-B515EEF54773}/>
</FieldRefs>
</ContentType><Field ID={67BC24C5-C864-4CE5-9855-B515EEF54773}
Name=Note1
StaticName=Note1
DisplayName=Note on version 1
Type=Note
Group=A feature upgrade attempt/>
</Elements>


  1. Change the version number of your feature by double clicking the feature node and change the feature version to 1.0.0.0 in the Properties window of your feature

  2. Deploy your solution and check that your content type is deployed successfully – and create a document library and attach the content type to it in the UI.

Make the extra field for the Content Type for version 2.0.0.0

For version 2.0.0.0 we will add an additional custom field for our content type and make the initial configuration of our feature ready for upgrading to the new verison, so let’s hit it by adding a new Field Item to our Sharepoint project and package the project to make it ready for the upgrade-celebration:

  1. Right-click the project-node of your Visual Studio Project and add an Empty Element called Version2Fields. It contains an element.xml, in which you put the following field, which will be the additional field of our feature in version 2.0.0.0:

<?xml version=1.0encoding=utf-8?>
<Elements xmlns=http://schemas.microsoft.com/sharepoint/>
<Field ID={67BC24C5-C864-4CE5-9855-B515EEF54774}
Name=Note2
StaticName=Note2
DisplayName=Note on version 2
Type=Note
Group=A feature upgrade attempt/>
</Elements>

  1. Expand your feature node untill the template.xml appears…open it. This is basically your feature without all the properties in it. Place your cursor between the open and close feature tag and add an UpgradeActions element with a corresponding closing element.
  2. In the UpgradeActions place a VersionRange to tell the versions you are upgrading from and to. Give it the properties BeginVersion=”1.0.0.0″ and EndVersion=”2.0.0.0″.
  3. Between the versionrange you can specify what will happen when we are upgrading from version 1 to 2. In our case we will add an additional elementfile, so insert a ApplyElementManifests and put a ElementManifest inside here with a location of your additiona element file
  4. Furthermore we need to add this field to the content type we just made – so add an AddFieldToContentType and give it the id of the content type and the field and specify whether to pushdown the field to all content types inheriting from the specified content type. Your Feature file should look something like this

<?xml version=1.0encoding=utf-8 ?>
<Feature xmlns=http://schemas.microsoft.com/sharepoint/>
<UpgradeActions>
<VersionRange BeginVersion=1.0.0.0EndVersion=2.0.0.0>
<ApplyElementManifests>
<ElementManifest Location=Version2Field/Elements.xml/>
</ApplyElementManifests>
<AddContentTypeField
ContentTypeId=0x0101009214903b71c048a0ba7a7ec3dff0d9dd
FieldId={67BC24C5-C864-4CE5-9855-B515EEF54774}
PushDown=TRUE/>
</VersionRange>
</UpgradeActions>
</Feature>

  1. Double-click your feature and change the version to version 2.0.0.0
  2. Right click your project and chose Package to package your solution

Upgrade your solution and feature in the farm

To upgrade your solution in the farm can be done via stsadm, custom code or PowerShell – and since one of the coolest parts of Sharepoint 2010 is Powershell, find your favorite PowerShell Editor (I User PowerGUI) and fire the following Powershell script with the path to your solution and the name of your solution

Update-SPSolution -Identity TheUpgradeableCT.wsp -LiteralPath C:\devprojects\TheUpgradeableCT\TheUpgradeableCT\bin\Debug\TheUpgradeableCT.wsp –GACDeployment

This alone isn’t enough to upgrade it – you to call a certain method to upgrade your feature – and this can be done via psconfig or custom code in any way you prefer….and I prefer the code attempt, so fire up a new instance of Visual Studio 2010 and make yourself a Console application (remember to change it to 64 bit build and reference Microsoft.SharePoint.dll):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace UpgradeTheContentType
{
class Program
{
static void Main(string[] args)
{
using (SPSite currentSite = new SPSite(“http://intranet”))
{
foreach (SPFeature feature in currentSite.QueryFeatures(SPFeatureScope.Web,true))
{
if (feature.Upgrade(false) != null)
{
Console.WriteLine(“Feature “ + feature.DefinitionId.ToString() + ” failed to upgrade!”);
}
else
{
Console.WriteLine(“Feature “ + feature.DefinitionId.ToString() + ” was successfully upgraded!”);
}
}
}
}
}
}

This bit of code queries every feature at the web scope at http://intranet for features in need of an update and actually tries to update them

So that’s all…check your content type and your list instance for the new field – which should be present. In the next post I will make the FeatureUpgrading of the FeatureReceiver a bit clearer. Until then the code is available at my DropBox at  http://dl.dropbox.com/u/6050844/Blog/UpgradeContentTypes.zip

Have fun

Peter

PowerShell and Sharepoint 2010 – Part 2 : Reading the ULS log

20. April 2010

Some part of problem solving in Sharepoint is done through the ULS logs which by default is placed in the Logs-directory of the RootFolder of your Sharepoint installation. In Sharepoint 2007 you need to manually search the text-files for the terms that might have caused problems for the user and then try to connect the event log and the uls-logging times and figure out what happened. While this is still the truth in SharePoint 2010 PowerShell has made it increasingly easier to scan the log for whatever error you might have. So grab a PowerShell command prompt and type Get-SPLogEvent and watch the complete ULS appear across your screen. This is not very helpful and takes a bit of time, so we need to do some filtering.

Date and time filtering

First of all we need to do some date-filtering. If you only want errors from the last five minutes, you can filter by giving the command a start property in a format like the following: Get-SPLogEvent –StartTime (Get-Date).AddMinutes(-5) which obviously will take and calculate a start time from current time (which is provided by the get-date method, and the add negative five minutes, which will give the log for the last five minutes. Note that an endtime is available in the exact same way

Chosing what columns to see

Still I get no idea, what the error is – only stuff like EventID, The time the error occurred and stuff like that appeared in the above command. This must be available in a more detailed form. And of course it is. By sending the results of the Get-SPLogEvent command into a select statement, you can choose exactly what columns to show. So grab the PowerShell command again and write Get-SPLogEvent –StartTime (Get-Date).AddMinutes(-5) | select timestamp, message and you will get the timestamps and messages of all messages from the last 5 minutes. Available columns are:

  • TimeStamp
  • Continuation
  • Process
  • ThreadID
  • Area
  • Category
  • EventID
  • Level
  • Message
  • Correlation
  • Context

 

So a select * instead of select message will return every field in a format not very nice J

So final thing is to decide what columns you like, grab them and format them in a usefull way. Format-table I excellent for this, and passing the following command is often usefull: Get-SPLogEvent –StartTime (Get-Date).AddMinutes(-5) | select * | Format-Table –Wrap

Filtering on these fields

A filtering on any of the fields above is available to prevent admins from looking at everything, when they have an idea of where to look. Especially the new correlation id is handy to filter. It is provided on nearly any error message in the user interface and provided again in the log files. If you want to query the logs for a specific error you can do it by providing the SPLogEvent –StartTime (Get-Date).AddMinutes(-5)| Where-Object {$_.Correlation –eq “yourFancy CorrelationID”} | select timestamp, process, level, message, correlation | Format-Table –Wrap

Have fun J

Enabling State Service in SharePoint 2010

21. March 2010

State Service in SharePoint is a service that keeps temporary data across http requests in a SQL database, and is required in Sharepoint 2010 if you want to edit your list-form in Infopath 2010. However, it seems very difficult to enable this unless you use the farm configuration wizard, which basically creates a database and an application pool where you have no control of the names. If you want control, you’re in need of PowerShell – so here is a tiny very un-debugged PowerShell script I use every time I have a clean Sharepoint 2010 install.

In short terms it enables the service, and creates a service application and puts it in the default proxy group:

Write-Host ******************************************************* -ForegroundColor Blue
Write-Host * Session State Enabler for Sharepoint 2010 -ForegroundColor Blue
Write-Host ******************************************************* -ForegroundColor Blue

#Check if the Sharepoint snapin is enabled
$spSnapin = Get-PSSnapin| Where-Object{$_.name -eq ‘microsoft.sharepoint.powershell’}
if($spSnapin -eq $null)
{
    Write-Host adding Sharepoint Snapin -ForegroundColor Green
    Add-PSSnapin microsoft.sharepoint.powershell
}

$StateServiceApp = Get-SPStateServiceApplication
$stateService = Get-SPSessionStateService

if($stateService.SessionStateEnabled -eq $false)
{
    Write-Host Starting the service -ForegroundColor Green
    $dbName = Read-Host “Enter service database name”
    Enable-SPSessionStateService -DatabaseName $dbName

 

}

if($StateServiceApp -eq $null)
{
    Write-Host Session State disabled -Starting Session state -ForegroundColor Green
    $dbName = Read-Host “Enter serviceapplication database name” 
    $StateServiceApp = New-SPStateServiceApplication -Name “State Service application”
    New-SPStateServiceDatabase -Name $dbName -ServiceApplication $StateServiceApp
    New-SPStateServiceApplicationProxy -Name “State Service Proxy” -ServiceApplication $StateServiceApp -DefaultProxyGroup

    

if($SessionState.SessionStateEnabled -eq $true)
    {
        Write-Host Session State Started -ForegroundColor Green
    }
    else
    {
        Write-Host Session State did not start successfully -ForegroundColor Red
    }
}
else
{
    Write-Host Session State already enabled -ForegroundColor Green
}

Have fun J

PowerShell and Sharepoint 2010 – the introduction

6. March 2010

Powershell is a new addition to SharePoint 2010 – and to spend a few hours becoming familiar with the PowerShell commands will definitely save you a minute or 10 now and then in your daily life with SharePoint 2010. In this first post, we will get in touch with PowerShell and start out with a few “Hello World of PowerShell for Sharepoint” scripts, and the later – if I hopefully find the time – I wil make a deeper dive into this world. So let’s hit it – let’s SharePoint….!!!!

First of all we need a fancy command prompt – to get it click Start | Run and in the box type cmd and click OK – and BAM – you have a nice command box ready for use. To make it a powershell command type powershell and press enter

To communicate with the host(i.e making the prompt write information for you) you have to use the command Write-Host. So typing Write-Host Hello World at the prompt will make it send you a message. Actually you can format it very basically. –foregroundcolor green will eg. Make the text green and you also have a backgroundcolor you can play around with. If ever in doubt what parameters a certain powershell-command takes write get-help and the name of the help function will help you.

This is very basically what you needs of information of PowerShell to get rolling with PowerShell for SharePoint 2010 – so let’s hit it and get some information regarding SharePoint in the box. To get to that point we need some extra information regarding Powershell – and that is that the functionality you can use is depending on what snap-ins you have loaded. A snap-in is no more than a bunch of functionality in one package – and we need to load the ones for SharePoint – to do that type Add-PSSnapin Microsoft.SharePoint.PowerShell at the command prompt.    

To get a list of commands available type Get-command and nearly everything which includes an SP will be sharepoint-related. However, this is quite a few –so to get a document with all of them, type get-command –pssnapin Microsoft.sharepoint.powershell > c:\commands.txt and a nice notepad-doc will be created for you at the c-drive including all of the commands available.

A lot of gets and sets are present – so try to write Get-SPWebApplication at the prompt – and notice that a list of Web Applications with DicplayName and Urls from the farm will appear. Nice And easy J

Basically there are two important kind of PowerShell commands for SharePoint – the ones starting with GET-SP – which gets you something and NEW-SP which creates something. If you want to create a new WebApplication this can be done with the New-SPWebApplication command – so try to type Get-Help New-SPWebApplication at the command prompt to see what is needed for a new Web Application – the following is returned

So typing New-SPWebApplication –name “Qwert Intranet” –ApplicationPool “Qwert Intranet” –ApplicationPoolAccount q\administrator –DatabaseName SharePoint_Qwert_Content_Intranet –HostHeader Intranet.qwert.dk –port 80 –url http://intranet.qwert.dk

After thinking a while – your web application is created – confirm by writing Get-SPWebApplication at the command prompt and your new web application will appear.

Deleting the web application is providing by Remove-SPWebApplication – try typing get-help Remove-SPWebApplication to read more about the properties – the command below deletes your web application – note that you have to confirm the action.

A final Get-SPWebApplication will confirm the deletion.

Figuring out how to make a site definition with the new Wiki-frontpage

23. December 2009

The new Wikii-frontpage of the Sharepoint foundation Team sites is a very user friendly feature since you will have the best possibilities of creating custom content in your pages without having to using the good old Content Editor Web Part from WSS 3.0. It is situated in a library called SitePages.

As a siteAdmin you can enable this in site features by activating the Wiki Page Home Page feature on every site needed…..but how the heck is it done from a site definition?

Reverse engineering is the way ahead….and the standard team site has the function enabled, so a good place to start searching is in 14\template\sitetemplates\sts\xml where the ONET.XML for the team site, blank site and document workspace resides.

Configuration 0 is the teamsite, and at a first glance there are no lists called SitePages and no modules ghosts a page called home.aspx. Looking a bit better the following lines might do the trick:

<WebFeatures>

<!– WikiPageHomePage Feature –>

<Feature
ID=00BFEA71-D8FE-4FEC-8DAD-01C19A6E4053 />

</WebFeatures>

…so basically it is a webfeature and adding this line in your WebFeatures of your site definition will make a sitepages library for your sitepages and a default page called home.aspx. It will also create a library called Assets for e.g. pictures.

Enabling the Developer Dashboard in Sharepoint 2010

23. December 2009

Introducing the Developer Dashboard in Sharepoint 2010, developers will get the tool they were looking for: A dashboard saying how long time the custom code took to execute, what queries were ran at the sql server and a lot of other fun stuff…..only problem…..it pro’s and end users doesn’t care about it, and therefore it is disabled by default – and there is no button the enable and disable it.

How is it done then…..there are three options, stsadm, PowerShell or custom code. In this blog-post we will be dealing with the code-option

The code-attempt

Open Visual Studio 2010, create a new Console Applicaton and make sure the .Net Framework 3.5 is chosen in the top…..SHarepoint has no idea of what .Net Framework 4.0 is.

Change the build setting of the project from x86 to any CPU in the project properties and save them.

Include the namespace of sharepoint administration by pasting the following just beneath the other using-statements:

using Microsoft.SharePoint.Administration;

And finally paste the following lines of code in your Program.cs files in static void main

SPWebService contentService = SPWebService.ContentService;

contentService.DeveloperDashboardSettings.DisplayLevel = SPDeveloperDashboardLevel.On;

contentService.DeveloperDashboardSettings.Update();

This will enable the developer dashboard for the entire farm – and it will look something like this:

Have fun J

List form from Infopath 2010 is blank

22. December 2009

Well…..one of these you use a couple of hours to solve and looking back you know it should only have lasted 20 minutes, if your brain had been pressent :-)

Here we go….when creating a new list item in SHarepoint 2010 in a list with a list form edited in Infopath 2010 you get a pop-up with no fields and no headings – even though you know you have placed several fields in it.

The trick is called “System State” and is the same as in Sharepoint 2007 where you got it from the Shared Service Provider, but since there is no Shared Service Provider in Sharepoint 2010 you need to find it another place.

Open the Central Administration and click on configuration wizard in the quick launch. Start the configuration wizard and make sure System State is checked on the services page. After 5 minutes every Infopath form rendered like a dream.

Actually there is another way of doing this, if you are not the “wizard-kind-of-Sharepointer” and this is through PowerShell – I have searched but haven’t found a “Enable Session State” in the Central admin. The cmdlets are Get-SPSessionStateService, which returns a true or a false indicating if it is enabled or not – and if it is not, you can enable it with the cmdlet Enable-SPSessionStateService, which takes a lot of parameters – and the only mandatory is Databasename.


Follow

Get every new post delivered to your Inbox.