Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

Posts Tagged ‘web part’

Target Audiences of Web Parts

Posted by Jean Paul on August 27, 2015

In this article we can explore the Target Audiences property of web part. This is a less used property.


You have a list which has N number of web parts. You need to hide web few parts based on the user role.


How to achieve this?


You can use the property Target Audiences of web parts for this.


Please follow the steps below to experiment this feature. Create a new page & add 3 Image Viewer web parts into it.


Following are the 3 web parts.


Now add the above 3 images into Site Assets library and link them to the web parts.

Choose the Web Part > Edit Web Part > Advanced > Target Audiences Property to Site Owners, Site Members, Site Viewers groups respectively.


Save changes. Now refresh the page.


If you are in the Site Owners group, you will see the following web part alone.


If you are in the Site Members group, you will see the following web part alone.


If you are in the Site Visitors group, you will see the following web part alone.

This concludes our example with Target Audiences property.


Power Users can use the Edit Page option to roll back the Web Part property. So preferably this method should not be exposed to them.


In this article we have explored the Target Audiences property.

Posted in SharePoint, SharePoint 2013 | Tagged: , , , | Leave a Comment »

Web Part Maintenance Page

Posted by Jean Paul on April 5, 2015

In this article we can explore the web part maintenance page feature of SharePoint.


While working with web parts in a page, we might encounter a situation where one of the web parts malfunctioned and the whole page stopped from loading.


We may wish to open the page in edit-mode and fix the web part. But, in few cases the edit-mode itself won’t work leading the user to re-create the page with web parts.

Maintenance Mode

To our help there is a maintenance mode for pages. It helps to close any malfunctioning web part from the page. To open the page in maintenance mode we need to use the query-string contents=1


For the following URL I am using the maintenance mode.


You can see the page will be displayed as below.


Here you can select a web part & close / reset / delete it.

There is an option named Go Back to Web Part Page to return to the non-maintenance page.


You need to have appropriate permissions to use the maintenance mode.



In this article we have explored the web part maintenance page feature of SharePoint.

Posted in SharePoint, SharePoint 2013 | Tagged: , , | Leave a Comment »

Sandboxed Web Part, Developer Dashboard & Resource Quota

Posted by Jean Paul on September 24, 2013

BrandCache – Speedup SharePoint

BranchCache is a WAN bandwidth optimization technology. Advisable in the case of branch office clients connected to head quarters servers. We can use this along with SharePoint Implementations as well.


Advantages of BranchCache are:

1. It reduces network traffic

2. It increases response time

BranchCache works by obtaining unique hash of documents from server & storing the document along with cache. The next time when user requests the same document, the response time will be faster as the document hash is same, it will be provided from the cache.

There are 2 types of caching in BranchCache:

1. Distributed Cache where multiple clients will store the cached documents & clients will serve each other in providing cached document.


2. Hosted Cache where each client will check the cache for a local server & get the document from cache or server. If from server, it will store a copy in the server for later retrieval by clients.



Let us take a scenario where a 10 MB file is taking 1 minute to download from the server, without BranchCache.

The delay for 100 downloads will be:

1. 1 minute for 1st download

2. 1 minute for 2nd download

3. 1 minute for 100th download

If we apply BranchCache, the delay will be:

1. 1 minute + Cache time for the 1st download

2. 1-2 seconds for the 2nd download (but depends on local n/w speed & request concurrencies)

3. 1-2 seconds for 100th download

BranchCache is optimized when Large Video files, Employee Handbook, Leave Request Forms & other documents which have less chance of modification & more chance for re-downloads.


1. Configuration overheads of clients & servers

2. Although the repeated downloads are faster, the first download increases download time as there is download & caching happening.


Supported operating systems combinations include:

1. Windows 7 clients and Windows Server 2008 R2

2. Windows 8 clients and Windows Server 2012



In this article we have explored a Speed Optimization technique which can be applied for SharePoint 2010 implementations as well.

Posted in SharePoint, SharePoint 2010, Uncategorized | Tagged: , , , | Leave a Comment »

Programmatically Refresh Content Query Web Part

Posted by Jean Paul on September 17, 2013

In this article we can explore a real life scenario of refreshing Content Query Web Part programmatically.


I hope the reader is having good knowledge of:

1. SharePoint page editing

2. Web Part insertion

3. Web Part creation using Visual Studio

4. Web Part Deployment


Following are the scenario items:

1. A home site with 2 web parts, project button web part & Content Query (CQ) web part

2. 2 project sites, each with Tasks list

3. On click of button, the particular project tasks should be shown in the CQ web part

How to achieve the same?


What is Content Query web part?

Content Query web part allows list querying & it is a part of Enterprise Content Management (ECM) functionality. You can add the web part from the Content Query category. You need to enable the Publishing feature to access the web part. Within code, the web part is called Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart

Step 1: Create Project Sites

Create 2 project sites of template Team Site & add some tasks into it. Make sure you remember the URLS.

The Project 1 Tasks list:


The Project 2 Tasks list:


Step 2: Design Project Buttons web part

Open Visual Studio & Perform the following:

1. Create a new Visual Web Part project of type Farm Solution

2. Add reference to Microsoft.SharePoint.Publishing namespace

3. Delete the existing web part inside the project

4. Create a new Visual Web Part & name it as ProjectButtonsWebPart

5. Replace the Page Load event with following code.

private static Dictionary<string, string> _projectUrl;

protected void Page_Load(object sender, EventArgs e)


_projectUrl = new Dictionary<string, string>();

_projectUrl.Add(“Project 1”, “/projectsite1”);

_projectUrl.Add(“Project 2”, “/projectsite2”);

// Create UI controls for Projects

foreach (string project in _projectUrl.Keys)


Button button = new Button();

button.Text = project;

button.Click += button_Click;




6. Add the following method for button click event handler.

private void button_Click(object sender, EventArgs e)


string url = _projectUrl[(sender as Button).Text];

SPSite site = SPContext.Current.Site;

SPWeb web = site.RootWeb;

web.AllowUnsafeUpdates = true;

SPLimitedWebPartManager manager = web.GetLimitedWebPartManager(“SitePages/Home.aspx”, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

foreach (System.Web.UI.WebControls.WebParts.WebPart w in manager.WebParts)

if (w is Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart)


Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart cwp = (w as Microsoft.SharePoint.Publishing.WebControls.ContentByQueryWebPart);

SPWeb targetWeb = site.OpenWeb(url);

cwp.WebUrl = targetWeb.ServerRelativeUrl;

//set the guid of the list

cwp.ListGuid = targetWeb.Lists[“Tasks”].ID.ToString();

PublishingWeb pweb = PublishingWeb.GetPublishingWeb(targetWeb);




ClientScriptManager cs = Page.ClientScript;

String csName = “ReloadClientScript”;

Type csType = this.GetType();

if (!cs.IsStartupScriptRegistered(csType, csName))


StringBuilder csText = new StringBuilder();

csText.Append(“<script type=”text/javascript”>”);

csText.Append(“this.location.reload(); </”);


cs.RegisterStartupScript(csType, csName, csText.ToString());



7. Ensure you have the following namespaces included.

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Publishing;

using Microsoft.SharePoint.WebPartPages;

8. Resolve any namespace issues like System.Web.UI.WebControls.WebParts.WebPart

9. Build the project

10. Deploy the project

11. Insert the Project Buttons web part to the home page. It looks like below.


Step 3: Insert the Content Query web part

Now we can insert the Content Query web part into the home page. Open page in edit mode & insert web part from the Content Rollup group as shown below.


Edit the web part & make the Presentation > Link property as empty.


Now the page looks like:


Step 4: Test the buttons

Now click on the Project 1 button & you should see the Content Query web part updated with tasks.


Now click on the Project 2 button & you should see the tasks changed with Project Site 2.


To summarize the activities, please note the following:

1. The Project Buttons web part have 2 hard coded paths inside it

2. On click of the button, the Content Query web part is refreshed by changing the List ID property

3. After the button click is processed, a client side startup script is registered to reload the page

4. Now on clicking the button, the content query web part will display tasks list from the corresponding project site.



In this article we have explored a typical real world scenario of refreshing a web part from another web part. I hope this will be useful to you in SharePoint development.

The source code can be downloaded here.

Posted in SharePoint, SharePoint 2010 | Tagged: , , , , , , , | Leave a Comment »