This morning I was trying to create a new style in the itemstyle.xsl stylesheet to use within the content query web part (CQWP). I needed a custom style to display a list of announcements, some of which had content and others didn’t and this style was to improve this output.
The problem is that the ‘Body’ column of an announcement or more importantly the ‘rich text’ field type is never really empty. Even when the column genuinely empty and has no rich text content, a hidden HTML element (a div) exists and acts as a wrapper for any content. As a result, if you try and use a typical ‘if equals null’ statement to hide the rich text column it won’t work because of this hidden element.
An empty rich text column on SharePoint 2010 always has 37 characters as shown below.
With SharePoint 2007 the rich text column has 65 characters when empty, again as shown below.
The solution, in the end, was to use the string-length function to determine if the rich text column was longer than the standard 37 characters on SharePoint 2010 as identified above.
To get a list of all the managed paths for a given web application we use the Get-SPManagedPath cmdlet as shown below.
Creating a new explicit path
Explicit managed paths only allow one site collection to be created at a specific path. An example of this is the root site collection of a web application which has an explicit managed path of “/” (https://sharepoint.jcallaghan.com).
To add a new explicit managed path to a web application we use the New-SPManagedPath cmdlet and include the -Explicit parameter.
Adding a wildcard managed path
Wildcard managed paths allow one or more site collections to exist at a specified path. This is the same as the default ‘sites’ managed path that we should all be familiar with (https://sharepoint.jcallaghan.com/sites/projectxyz).
To add a wildcard managed path we run the command as we did for an explicit managed path however we don’t include the -Explicit parameter.
Removing an existing managed path
There may be times when you need to remove managed paths. This can be done by running the Remove-SPManagedPath cmdlet and specifying the name of the managed path to be removed and what web application to remove it from. When removing a managed path you will be prompted to confirm the removal action – this can be silenced by adding -confirm:$false to the command.
Using the SPManagedPath nouns in PowerShell we can get a list of existing managed paths, create explicit or wildcard managed paths and also remove existing managed paths for a given web application.
Today I had a requirement to remove all the headings and links from the quick launch navigation of hundreds of SharePoint sites. The sites were being provisioned as part of a PowerShell deployment script that was deleting the default list and libraries. Going through each of these sites manually was not an option – so I edited the deployment script to include a function to remove the headings for me.
I remembered doing something similar to this back on SharePoint 2007 but I didn’t have access to the previous script or project and instead had to research the subject for a while to find what I needed.
A post from Get-SPScripts supplied me with what I was after, although it was part of a much larger script. So I picked away at their code and made it into the following PowerShell function to re-use in other projects.
The above Remove-SPQuickLaunchLinks function will remove all headings and links from the SharePoint quick launch for a particular site.
The need to backup or download SharePoint solutions or WSPs from SharePoint come’s up from time to time. This usually crops up for me when upgrading client environments, and they have forgotten where they put their original solutions, or there is a discrepancy as to which version they installed.
To download the solutions from the config database run the following PowerShell script. This will save all of the solutions stored in SharePoint’s config database to a directory (“C:\Solutions”) on the local machine.
Many people have said to me “your using WordPress for your blog but you’re a SharePoint Consultant” and my response is typical “but why must use SharePoint – I guess you also have a problem with me using a Mac?”.
Yes, I do work with SharePoint – in fact, it goes beyond just working with it but we won’t go there. I have developed websites for many years and typically chosen to build these on the WordPress platform – it’s adaptable and responsive to the differing requirements and yet it doesn’t need weeks of custom development. Not only that but it was built for blogging and the user interface is more in tune to writing blog posts. Secretly I knew if I used SharePoint for my blog it would become more of a job than a hobby with all the extra work it would need.
SharePoint is just not the blogging platform for me – let’s just say when I’m blogging I want the night off!