Archive for the ‘SharePoint 2010’ Category

Differentiating File/Folder in SharePoint Eventreceiver

EventReceiver

You can hook SharePoint eventreceivers to lists and libraries to execute custom code whenever a new document is being uploaded to a document library. The ‘ItemAdding’ event fires when a user adds a new document to a library, but also whenever a new folder is created. However, due to the vast variety of ways to upload a document (one document, multi-document, WebDAV, Office, WebService, etc.), the event always seems to behave a little different.

Having a reliable way to check whether the user added a new document or created a new folder in a document library is key for a solid eventreceiver.

(more…)

Reading SharePoint querystring values in JavaScript

QueryStringJavaScript

JavaScript is becoming more and more popular as a language for SharePoint solutions. Time to get familiar with the built-in JavaScript repository. I have seen quite of different ways to retrieve querystring parameter values in JavaScript, but SharePoint features it’s own function ‘_spGetQueryParam(p)’.

(more…)

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…)

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…)

Enumerating SharePoint groups and group members through its webservices using PowerShell

Enumerating SharePoint groups and group members through its webservices using PowerShell

SharePoint offers a large variety of webservices and consuming such a webservice with PowerShell takes only a few lines of code:

$SPService = New-WebServiceProxy -Uri ($WebUrl + "/_vti_bin/SomeWebService.asmx?WDSL") -UseDefaultCredential
$SPService.SomeMethod()

You can use PowerShell to enumerate all SharePoint groups and save them to a CSV-file without logging in to the SharePoint server.

(more…)