Wednesday 27 February 2013

Error - All items returned by SPQuery

When you form your caml to be used with an SPQuery remember not to include the <Query></Query> tag. Begin with the <Where> tag.

Correct - The following will only return the item with the title "Listitem One":
  • <Where><Eq><FieldRef Name='Title' /><Value Type='Text'>Listitem One</Value></Eq></Where>
Wrong - The following will be some weird reason return all list items:
  • <Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>Listitem One</Value></Eq></Where></Query>

Tuesday 26 February 2013

Create a cross site lookup field without code

Out of the box you cannot create a cross site lookup field in SharePoint. You must create a new field type (code) to do this.
However the other day I came across a easy workaround where you don't have to code anything:

  1. Create your lookup list on the parent site
  2. On the parent site create a lookup site column that looks into the list created in step one.
  3. On the subsite create a list that should use the information stored in the list on the parent site.
  4. Add an existing column to the list (the column created in step two).

See also: Creating a cross site lookup field without code


Tuesday 19 February 2013

Error occurred in deployment step 'Activate Features': The parent content type specified by content type identifier 0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D does not exist.


  • Solution: Activate the publishing features.

In this case you probably have a pagelayout that inherits from the "Article Page" content type (which is a part of the publishing pages).

Wednesday 13 February 2013

Getting the full url in the code behind of a SharePoint page in the layouts folder

The issue

I had a situation where I had created a sub site collection and a deployed a asmx websercice to a subfolder in the layouts folder.
From codebehind I used HttpContext.Current.Request.Url to get the url of the web service.

If I in the browser entered the address:
  • http://server/sites/subsitecol/_layouts/webservice.asmx
I got the url
  • http://server/_layouts/myfolder/webservice.asmx
in the codebehind. Notice it has omited the path to the sub site collection.

My workaround

The RawUrl contains the path to the sub site collection. However it is server relative, so I build the absolute url like this (there might be better ways to construct the absolute url):

var uri = new UriBuilder(HttpContext.Current.Request.Url);
uri.Path = HttpContext.Current.Request.RawUrl;
var absoluteurl = uri.Uri.AbsoluteUri;


Thursday 7 February 2013

Upgrade a feature with PowerShell

When you wnat to add new fields to an existing content type in SharePoint you make a new version of the feature - an upgraded version. You deploy the new wsp package with an SPUpdateSolution command.
But you are not done yet! It is only deplyed to the server. You must tell SharePoint explicitly too look for a new version of the feature, and upgrade the feature to this version.
Oddly you cannot do this through the interface - you must do it through code. This can be done in C#, (Visual Basic?), or in PowerShell.

To upgrade a feature in PowerShell you do this:

  • $s = Get-SPSite -Identity 'insert url of the web where the solution is deployed'
  • $features = $s.QueryFeatures('web',$true)
  • foreach($feature in $features){if($feature.DefinitionId -eq ‘72dc4341-4404-413c-b8ab-22e5723fdbec'){$feature.upgrade($true)}}

This will upgrade the feature with id "72dc4341-4404-413c-b8ab-22e5723fdbec".

Monday 4 February 2013

Your Search Cannot Be Completed Because This Site Is Not Assigned To An Indexer

I had this very annoying error when trying to search my SharePoint Server 2010 single server development machine through code (using the KeywordQuery and FullTextSqlQuery classes).
The search crawler was running and searching from the SharePoint UI returned the expected results.

What you need to do is to...
  • Start the "SharePoint Foundation Search"service.
  • then go to the select "Manage Content Database Settings" page and select the server running the SahrePoint foundation search service at the drop down menu

Central Administration -> Application Management -> Manage services on server


Central Administration -> Application Management -> Manage Content Database -> (click on database name)



This was not intuitive to me as I was running SharePoint Server Enterpise. And the "SharePoint Server Search" service was already running. Also it strikes me as odd as you do not have the FullTextSqlQuery in SharePoint foundation - you need to have the Enterprise version.

Close and re-open web parts

If you wanna hide a web part for a while so that you can re add it to the page later without having to reconfigure all of it settings this is what you do:

Close the web part from the web part drop down menu (the arrow that appears in the top left cornor of the web part when you hover over it):




When you later wanna re enable it, you click add web part as normal,k however this time you click the "Closed webparts group" and add it from here: