Archive for 2012

Modify Permission Levels (using bitwise operators)

permission-level-teaser

The easiest way to create a new permission level in SharePoint is to copy and modify an existing permission level. For example, you can copy the ‘Contributor’ permission level and remove the ability to delete items by unchecking the corresponding option. SharePoint 2010 even provides a ready-to-use out-of-the-box button to copy existing permission levels.

However, modifying permission levels programmatically is a little bit less obvious as the SPBasePermission enumeration is implemented as a bit flag.

(more…)

Retrieving all (nested) members of a Group

Membership-teaser

You can assign permissions to users, SharePoint groups and Active Directory groups in SharePoint. While SharePoint groups cannot contain other SharePoint groups, it is possible to nest Active Directory Groups. The SharePoint method SPGroup.Users only returns users that are added directly to the SharePoint Group. I have written a small function that is able to retrieve all users of a SPPrincipal object, included nested users.

(more…)

A weather forecast WebPart using JSONP

Weather-WebPart-teaser

My previous post shed some light on JSONP and how it works. In this post I will describe how to create a cool SharePoint 2010 WebPart that shows weather forecasts. The actual forecast data is retrieved from the Yahoo Weather Service  using a JSONP call.

(more…)

Cross-domain webservice calls using JSONP

JSONP-teaser

The JavaScript class library for SharePoint 2010 enables developers to create rich SharePoint applications using pure JavaScript. If combined with the jQuery library, the power of JavaScript solutions is limitless,….. or isn’t it.

The Same Origin Policy prevents access to resources on other domains. Put simply; you cannot call a webservice from JavaScript that is hosted on another domain. There is however one exception to this claim; browsers allow the <script>-tag to call JavaScript files that are hosted on another domain. The technique JSONP exploits this opportunity.

(more…)

Weird bug while updating WelcomePage using C#

weird-bug-while-updating-welcomepage-using-c

You can change the WelcomePage of your site by updating the value of SPFolder.WelcomePage. However, you might experience some strange behavior if your are trying to update this value directly.
(more…)

Conditionally enable/disable Ribbon buttons based on user permissions

Conditionally enable-disable Ribbon buttons based on user permissions

Using custom action you can create your own ribbon elements. In a post I have published a while ago I showed how to add a button to the ribbon to generate a QR-Code. But what if you want your button only to be enabled under certain circumstances. For example; if the user has sufficient privileges.

(more…)

Checking user permissions: DoesUserHavePermissions vs. CatchAccessDeniedException

Checking user permissions DoesUserHavePermissions vs CatchAccessDeniedException

I recently had a nice discussion with a colleague about the best way to check if the current user has permissions to view a specified SharePoint list in a SP2010 site using C#.

 

 

Basically there are 2 ways to check for permissions:

1) SPSecurableObject.DoesUserHavePermissions

2) SPSecurity.CatchAccessDeniedException

This post  discusses both methods, proposes implementations and discusses the pro’s and cons.

(more…)

Using the SharedQueryManager to display Relevant Search Parameters in a WebPart

Using the SharedQueryManager to display Relevant Search Parameters in a WebPart

The SharePoint Search is powerful yet very complex. There are a lot of settings and parameters that influence the search results.

For example; did you know that the Culture used in the query is used to determine wordbreaker, stemmer, and thesaures? Search with the wrong Culture and you will get unreliable and strange search results. I have seen it happen at a customer; the documents were all written in Dutch but the search was configured to use the English Culture (en-US: 1033). Finding out why some documents were included in the search result while others are left out can be a challenge as you have to check every search parameter at WebPart level, Site level, and Service Application level.

(more…)

Changing the URL of an existing document library or list

Changing the URL of an existing document library or list

When you create a new list or document library in SharePoint the Name you supply for your new list is also used to in the URL. Characters like spaces are replaced by their HTML equivalents (%20). Changing the title of the list afterwards is easy, so is changing the URL of an existing list. You just have to know where to look. This post explains how to change both the title and the URL of existing lists and libraries using several techniques.

(more…)

Load an external JavaScript file on demand using a Custom Action in SharePoint 2007

Load an external JavaScript file on demand using a Custom Action in SharePoint 2007

I build a lot of SharePoint Solutions that use JavaScript to enhance user experience. Most of the JavaScript I put in dedicated .js files and deploy them to the 12-hive (or 14-hive) in the layouts-folder. Deploying a JavaScript file (*.js) layouts-folder of SharePoint and loading external JavaScript files (*.js) in SharePoint 2007 can be accomplished in a couple of ways.

(more…)