Archive

Archive for the ‘SharePoint’ Category

Updated – Approve or Reject multiple items in a SharePoint 2010 list

August 3, 2012 Leave a comment

I’ve updated the solution which allows for multiple items to be approved or rejected in a SharePoint 2010 list.  The original post can be found here.

The original solution was built to serve a specific purpose but due to the comments received I’ve now updated it to be more generic and made the following improvements.

  • The solution will work for almost any list or library.
  • It supports language packs and will be fully localised.
  • The source code is available.
  • The ribbon button will only appear if you have rights to approve items.
  • Resolved an issue with the modified by field appearing as the System Account.
  • Changed the way the button appears in the ribbon to use Tooltips.

These are the links to the compiled solution and the source code.

Categories: SharePoint

Site Navigation with a Content Query Web Part in a SharePoint Page Layout

November 1, 2011 Leave a comment

A brief on one of my current projects was to create left hand navigation for an new Intranet which was built up from the Pages library.  As is usual with Intranets, the content was spread across multiple publishing sites under a single Site Collection, hence each site had it’s own Pages library.  It’s a simple task to set this up for each page using the Content Query Web Part (CQWP) but ideally this should be part of a Page Layout that can be used on every site.  

The other requirement was that the Title of the Web Part should be that of the current site, so Information Technology if the user was view pages from that site, Operations for the Operations site etc.

Out of the box, this would not be possible as the CQWP is linked to a single library and it’s Title is set from the Web Part Properties. You obviously could add a CQWP to each page but this is inefficient and beyond most content editing users. So for a more elegant solution you’ll need to use Visual Studio to create your own Web Part, however the code is extremely straightforward and is derived from ContentByQueryWebPart. You will need to include a reference to Microsoft.SharePoint.Publishing.WebControls in your project which is in the Microsoft.SharePoint.Publishing namespace and the code below should be enough to get you up and running.

public class ContentNavigation : ContentByQueryWebPart
{
 protected override void CreateChildControls()
 {
   SPWeb web = SPContext.Current.Web;
   SPList list = web.GetList(web.Url + "/Pages");
   this.ListGuid = list.ID.ToString();
   this.ListName = list.Title;
   base.CreateChildControls();
 }

 protected override void OnPreRender(EventArgs e)
 {
   this.Title = SPContext.Current.Web.Title;
   base.OnPreRender(e);
 }
}

Once packaged and deployed, it’s then straightforward to create a Page Layout containing this web part.

SharePoint, JQuery and z:row when using Chrome

November 1, 2011 1 comment

I’ve recently been using JQuery with SharePoint web services quite extensively and initially had a few issues with Chrome not rendering when the same code works fine with IE.  With this post I’ll show you what you need to change for cross browser compatibility as there seems quite a bit of confusion around the web.

A lot of code examples use:


$(xData.responseXML).find("z\\:row").each(function(){

whilst this works in IE & Firefox, it won’t function in Chrome or Safari, but if you are using JQuery 1.5 or greater, change this line to the following and you’ll have a working solution in all browsers.


$(xData.responseXML).find("[nodeName='z:row']").each(function(){

Categories: JQuery, SharePoint

This page is not using a valid page layout in SharePoint 2010

October 18, 2011 Leave a comment

In this post, I’ll show you how to overcome the error ‘This page is not using a valid page layout’ when moving around content from one publishing site collection to another in SharePoint 2010.

It’s a problem I’ve come across a few times as it’s been around since MOSS.  It occurs if the relative path between site collections or web application is different and therefore breaks the link to PageLayout.  For example moving these pages:

http://sharepoint/sites/wiki/home.aspx

to a subsite

http://sharepoint/wiki/home.aspx

will result in an invalid relative link to the pagelayout, in this case it will be http://intranet/sites/wiki/_catalogs/…. so as you can see there is an erroneous sites reference within the link.

Initially it’s best to view the current Pagelayout assigned to each page, to do so you can use this script, replace [Site URL] with the url of the site containing your publishing pages.

$Site = "http://[Site URL]"

$web = Get-SPWeb -Identity $Site
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
{
  write-host $publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout]
}

To resolve the issue, I wanted a flexible solution which could work with any pagelayout or even replace them if needed and therefore opted for a script which used a simple search and replace.   In the following script, update the [Site URL], the [Search for] for the string to search for, for example the old link and [Replace with] for the new value, such as the new site.

$Site = "http://[Site URL]"
$SearchFor = "[Search For]"
$ReplaceWith = "[Replace With]"

$web = Get-SPWeb -Identity $Site
$publishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$publishingPages = $publishingWeb.GetPublishingPages()
foreach ($publishingPage in $publishingPages)
{
  $url = $publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout]
  if ($url -match $SearchFor)
  {
    write-host Updating Page Layout for $publishingPage.Name
    $newurl = $url -replace $SearchFor, $ReplaceWith
    $publishingPage.CheckOut()
    $publishingPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl
    $publishingPage.ListItem.UpdateOverwriteVersion()
    $publishingPage.ListItem.File.CheckIn("Corrected page layout URL", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
  }
}
Categories: Publishing, SharePoint

Create a blank publishing page in SharePoint 2010 for a print view or hosting in an iFrame

October 11, 2011 Leave a comment

There are a few occassions when a page’s content could be useful without the associated branding and navigation elements being visible.  For example if you want to create a print view or host SharePoint content in an iFrame.  In my case I wanted to host the Organization Browser web part within an iFrame using a Content Editor Web Part.  This would enable me to access the same page on multiple sites, getting different content by setting querystring values in the CEWP and overcoming the issue of adding querystrings to URLs breaking SharePoint navigation.

First you need to create a new masterpage using SharePoint Designer, to do this take a copy of your existing custom masterpage or default.master and name it blank.master. Edit the file in Advanced Mode and find the main table which starts with <table class=”ms-main”.  Now add this style=”display:none” tag to the end.  It should look something like this:

<table cellpadding=”0″ cellspacing=”0″ border=”0″ width=”100%” height=”100%” style=”display:none”>

Next find this content holder <asp:ContentPlaceHolder id=”PlaceHolderMain” runat=”server”></asp:ContentPlaceHolder> and copy this to the clipboard, delete it from it’s original location and place it under the closing tag for the main table.  Also, to avoid scrollbars appearing in my iFrame, I amended to the body tag to set scroll=”no”.

Checkin, publish and approve your new masterpage.  Now if you haven’t already, create the content which you wish to host in the blank master page, then return to SharePoint Designer.  Next we need to detach the content page from it’s Page Layout, so open the library which contains your content, select the file, right click  and choose Detach from Page Layout then click Yes to the warning.  If the library is under source control, click Yes to check it out.  Now right click again and choose Edit file in Advanced Mode.

Now replace this line:

<%@ Page language=”C#” Inherits=”Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c” meta:progid=”SharePoint.WebPartPage.Document” meta:webpartpageexpansion=”full” %>

with this:

<%@ Page language=”C#” MasterPageFile=”~/_catalogs/masterpage/blank.master” Inherits=”Microsoft.SharePoint.WebPartPages.WebPartPage,Microsoft.SharePoint,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c” meta:progid=”SharePoint.WebPartPage.Document” meta:webpartpageexpansion=”full” %>

Save the file and if all is well, you’ll see the content without branding and navigation.

As you can see from the changes, this content now inherits from Microsoft.SharePoint.WebPartPages.WebPartPage which enables the MasterPage to be set.  With Microsoft.SharePoint.Publishing.PublishingLayoutPage this isn’t possible without custom code overriding OnPreInit.

Approve or Reject multiple items in a SharePoint 2010 list

September 29, 2011 13 comments

I’ve updated this solution, an update to this post can be found here

The out of the box list approval feature of SharePoint is extremely useful, not just for documents but you can quickly create many business solutions using this functionality, especially where a workflow may well be overkill.

One drawback is that users have to review and approve/reject each item  individually and on a list with many items, this can be quick time consuming.  The way to implement this functionality would be a custom action on the ribbon and looking around the Internet, I found a great solution from Sohel Rana to do exactly this.

The only problem, was that this was not ready for prime time and as Sohel states, “The code is not just download-and-deploy mode. This is just a piece of how you can implement. You may need to fine tuning the code as per your needs. But I’ve tried to give the gist of how this can be done.” Therefore I decided to build on his ideas and create a new solution that is just download and deploy and has a more consistent SharePoint look and feel.

This is a farm solution, so it is deployed though Central Admin.  The feature is scoped at Web level so to enable this functionality active the feature in Site Features within Site Settings.

Once enabled you’ll find a new action on the ribbon bar which is active when multiple items are selected as shown below.

This will then create a dialog which uses the familiar SharePoint Approve/Reject item look and feel.

Clicking on OK will set all selected items to the approval status and the comment text is also applied to all items.  Any workflows that are in-flight on these items are cancelled.

 

Categories: SharePoint

SharePoint London Underground Tube Status Web Part

September 21, 2011 2 comments

This is a small web part I developed which displays the status of the tube lines which make up the Transport for London Underground network.   It could be a handy web part to fill in an area of a corporate Intranet, if of course the company happens to be based in London!

This consumes a TfL datafeed so your server will need Internet access and the solution needs to be deployed at the farm level.  I’m not going to post how you can deploy this web part but a generic farm solution deployment guide can be found here.  I’ve tested this on SharePoint 2010 only but should work fine on MOSS too.

The code doesn’t use Ajax and there is no automatic refresh.  More information about lines with problems will appears on a mouse over on the status.  I’ve not included the source but happy to post if it helps anybody, and I am considering writing a tube departure board web part showing the trains from a configurable station, so if this is of any interest then please leave a comment.

Download Tube Status Web Part

Categories: SharePoint, Web Part

Error an unhandled exception occurred in the Silverlight Application when creating SharePoint 2010 Sites

September 12, 2011 Leave a comment

When creating a new SharePoint 2010 site via the Silverlight interface, if you experience the Error, An unhandled exception occurred in the Silverlight Application there is a simple fix.

The problem is caused by the Silverlight application, attempting to communicate with the WCF endpoint using the Client Object Model when Security Validation is turned off for the web application.

To resolve, in Central Administration click on Manage Web Applications, highlight the problematic Web application and click General Settings from the ribbon.  Scroll down to Web Page Security Validation  and ensure Security Validation is On 

You will now be able to create sites using the Silverlight interface.

Categories: SharePoint, Silverlight

SharePoint 2010 – Database is up to date, but some sites are not completely upgraded

August 23, 2011 Leave a comment

In Central Administration, if you visit Upgrade and Patch Management, Review Database Status and notice some DBs have the status ‘Database is up to date, but some sites are not completely upgraded.’ follow the procedure below to rectify.

If you are attempting to upgrade the Admin Content Database then Get-SPContentDatabase will not work, or at least it didn’t for me so refer to the extra steps at the end of this article.

The upgrade status reflects the current state of the database and hence this is not resolved via PSConfig but  rather by PowerShell.  If you need to perform this on a production or any other important environment, make sure you have an agreed maintenance window plus backups before beginning!

  • Using the farm account or equvilently privileged user, start the SharePoint 2010 Management Shell
  • Enter $DB = Get-SPContentDatabase -Identity [ Your Database Name]
  • Now enter Upgrade-SPContentDatabase -id $DB
  • You’ll now be prompted to confirm, just hit enter to accept the default of Yes
  • The upgrade will begin and a percentage complete will be displayed

When the process completes, return to Manage Databases Upgrade Status in Central Admin and the status will not be No action required.

Upgrading the Admin Content Database

As stated at the beginning of this article, Get-SPContentDatabase will not work with the Admin Content Database so another method needs to be found.  As long as you know the DB GUID, you can still execute Upgrade-SPContentDatabase so a simple query of the Config database could be used to find this.  However a better solution is to use Powershell.

The following script iterates though all Content DBs for a given Web Application, so can be used to upgrade the Central Admin Content Database.  You will need to the replace <WA URL> in the script with your Central Administration URL.

$wa = Get-SPWebApplication -Identity "<WA URL>"
foreach($ContentDB in $wa.ContentDatabases)
{
   Upgrade-SPContentDatabase -id $ContentDB
}