SharePoint Tip – Fixing unresponsive Edit mode when trying to add content

This is a tip on how to solve the issue in the title. This can occur to you when you open a page for editing and focus your mouse on the main content area. Normally the content editor should become active in the ribbon but this may not happen or you just can not add content.

This can be due to a possible JavaScript library performing some action on the page or worse a webpart which is inserted within the content area. This webpart uses a JS library and functionalities which interfere with the SharePoint out of the box content editor. This happened to me with HighCharts.

The solution for this is to add the following URL postfix after you aspx page ?contents=1.

Next you should be able to select the webparts which you know are in your content area. Close those selected webparts (you may need  to check out the page). After this go back to your page and add new content. When you are ready then focus your mouse in the content area to add a new webpart. Your webpart should be under a category named something like “Closed webparts”. Add the webpart and everything should be OK. The webpart properties and state should have stayed as it where before it was closed.


SharePoint 2013 display templates for content webparts do not work

This problem may occur when you have a custom display template which you are modifying at some stage and updating it into SharePoint. If for some reason your template stops working what you need to do is go to the display template and modify its properties.

There you will find several options where you want this template to be used, such as search, content webparts etc.

So go and check your display templates properties and make sure you have selected where the template is to be used.

SharePoint problems fixed – Code tricks – Part 1


Wanted to post some code tricks regarding SharePoint. Tricks which I have had to do more than once and tricks that are not so common but hard and useful:

Retrieve available web templates from a web:

SPWebTemplateCollection wtc = topNewsSite.GetAvailableWebTemplates(1035);

Set web default page layout(when you create new pages):

PublishingSite pubSite = newPublishingSite(yourSiteCollection);


                            PublishingWeb pubWeb = PublishingWeb.IsPublishingWeb(yourPublishingWeb) ? PublishingWeb.GetPublishingWeb(yourPublishingWeb) : null;

                            if(pubWeb != null)


                                PageLayout pageLayout = pubSite.PageLayouts.FirstOrDefault( item => item.Name == “yourpagelayout.aspx”);

                                if(pageLayout != null)


                                    pubWeb.SetDefaultPageLayout(pageLayout, false);






Copy(Add), Modify a webpart from one page to another with changes to webpart display template

// temp variable for a MS webpart which we will copy from one page to another page

                    Microsoft.Office.Server.Search.WebControls.ContentBySearchWebPart newsWP = null;

                    // Get the needed page from your site and get that pages web part manager

                    using (var wpm = topNewsSite.Lists[“Pages”].Items[0].File.GetLimitedWebPartManager(PersonalizationScope.Shared))


                        // Search for the right webpart(you could use LINQ instead of a foreach)

                        foreach (var wp in wpm.WebParts)


                            // Check the type of the webpart

                            if ((wp is Microsoft.Office.Server.Search.WebControls.ContentBySearchWebPart))


                                // Make sure it is a ContentBySearchWebPart

                                newsWP = wp as Microsoft.Office.Server.Search.WebControls.ContentBySearchWebPart;


                                // Check that we have the right webpart

                                if (newsWP != null && newsWP.Title.Contains(“My News Webpart”))


                                    // Get the page you need where you want the web part to be copied

                                    SPListItem page = newWeb.Lists[“Pages”].Items[0];

                                    SPFile file = page.File;


                                    // Get the web part manager of the destination page where to copy the webpart

                                    using (var wpmNewsWeb = file.GetLimitedWebPartManager(PersonalizationScope.Shared))


                                        // Change the web part display template for a listing with paging

                                        newsWP.RenderTemplateId = “~sitecollection/_catalogs/masterpage/Display Templates/Content Web Parts/Control_ListWithPaging.js”;

                                        // Add the web part to the page

                                        wpmNewsWeb.AddWebPart(newsWP, “CenterZone”, 0);

                                        // Make sure to call this to save the changes to the webpart












Sharepoint: Hide alternative text from webparts with JQuery


This is a rather simple tip for those who might want to hide the alternative text from their webparts header. Add the following to your javascript file that is included into your environment:

$j(“.ms-WPTitle”).attr(“title”, “”);

What it does is simple. Searches for a class named ms-WPTitle that exist in the sharepoint webparts header. Then replaces all title attributes with an empty text.

New icon to CQWP – Content Query Webpart


So you may have wondered HOW to enable or add a new icon to a CQWP. Well aparently you can not do it through the user interface and you need to do some XSLT modifications. Here is what you need to do:

1. You need to download the following MS XSL file to datetime processing and add it into your XSLT file that displays your data:

The MS BLOG file

The XSL piece of code to add your XSL file, this will include the above downloaded file into your XSL file:

<xsl:import href=”/Style Library/XSL Style Sheets/date_templates.xsl”/>

2. Inside your XSL file that displays data(in the case of a CQWP lets say the item style XSL template) add the following lines:

<xsl:call-template name=”getDayDelta”>
<xsl:with-param name=”paramDateA” select=”@ArticleDate”/>
<xsl:with-param name=”paramDateB” select=”ddwrt:Today()”/>

<xsl:variable name=”article_date”>
<xsl:value-of select=”ddwrt:FormatDate(string(@ArticleStartDate), 1033,1 )”/>
<xsl:variable name=”today”>
<xsl:value-of select=”ddwrt:FormatDate(string(ddwrt:Today()), 1033, 1)”/>
<xsl:variable name=”date_diff”>
<xsl:call-template name=”getDayDelta”>
<xsl:with-param name=”paramDateB” select=”ddwrt:FormatDateTime(string(@PublishedDate),1033, ‘yyyy-MM-dd’)”/>
<xsl:with-param name=”paramDateA” select=”ddwrt:FormatDateTime(string(ddwrt:Today()),1033, ‘yyyy-MM-dd’)”/>

The above was meant for a CQWP that would lift the latest blogs inside a blog site. Notice the @PublishedDate parameter. This can be @ArticleDate or @ArticleStartDate etc. What you need to make the date difference calculations.

The date_diff XSL variable will hold the date time calculation between the blog post published date and the present date. Then you can use this value to determine when to show the New icon.

3. Add the logic to display the New icon. The below logic tells that if the items is less than 7 days old you need to display the New icon.

<xsl:if test=”$date_diff &lt; 7″>
<img src=”/_layouts/1033/images/new.gif” alt=”New!” />

Sample in the XSL Blog title:

<div class=”blogListPostBlock”>
<!– Title –>
<a style=”color: #295AC6;”>
<xsl:attribute name=”href”>
<xsl:value-of select=”$SafeLinkUrl”/>
<xsl:value-of select=”$DisplayTitle” />
<xsl:if test=”$date_diff &lt; 7″>
<img src=”/_layouts/1033/images/new.gif” alt=”Smiley face” />

Also please take into consideration that this is for the LCID language ID 1033 English  You need to make sure it fits your language if you wish to use a different language translation for New icon.

Resources: SharePoint WebPart(s)

Adding Group and Quick Add Groups to your custom webpart programmatically 

SharePoint 2007 & 2010 development: How to remove a bad webpart from a page?

Problems with webpart after webpart is upgraded using Stsadm & Upgradesolution

Let the SharePoint Search web parts use an other Ranking Model

QueryStringPageViewer WebPart for Sharepoint – Mads Nissen

Inconvenient programmatically exporting Web Parts – Waldek Mastykarz

Programmatically Add ListViewWebPart with Customized View | Of Ones and Zeros

Stefan on SharePoint | Add Web Part to Page Programmatically

Quick Tip: Provisioning Web Parts to a Page – The SharePoint Guys – Site Home – MSDN Blogs

How the XsltListViewWebPart in SharePoint 2010 can be a real performance killer « Jaap Vossers’ SharePoint Blog

How to Add Web Parts to the Page Programmatically | Salaudeen Rajack’s SharePoint Diary

WebParts | Ketul’s Weblog

Presence Indicator:

sharepoint – Adding presence indicator to a custom web part – Stack Overflow

How to Display Presence Indicator in Custom Webparts « ahmedmadany

How to add Microsoft Office Communicator user presence icon to custom page/web part in SharePoint

Enabling Presence Information in SharePoint with Microsoft Communications Server 2010 – Programing4Us – Enterprise

Content Query Webpart – CQWP:

Formatting the Content Query Web Part and Removing HTML tags

SharePoint: Customize Content Query output with XSLT

How to: Display Custom Fields in a Content By Query Web Part

How to: Customize the Content By Query Web Part by Using Custom Properties

CQWP does not display list with custom datasheet

Extending Content Query Web Part with custom data – Waldek Mastykarz

Customizing the Content Query Web Part and Custom Item Styles