Step by Step: How to Assign Unique Item Permissions in a Task List Using Custom Code

Written by Denis Stadler on . Posted in Custom Development

The business requirements are quite clear in this case:

  • There is a task list that should be used for work assignments management
  • Only the site administrators can modify the task list items
  • The person(s) in the Assigned To field must have the security rights to edit only that item

The solution: a custom event receiver that modifies the item permissions.

Let’s create a new Event Receiver SharePoint project in Visual Studio with the following coordinates: List Item Events as type, Tasks as event source and item added and updated as events to handle.
item-added-item-updated

How to Save Configuration Data in SharePoint Development

Written by Denis Stadler on . Posted in Custom Development

When we develop custom application over the SharePoint platform, often we need to store different configuration parameters as: connection strings, e-mail addresses, URLs or different data parameters.

In SharePoint we have the following possibilities to store the configuration data (I will enumerate them based on my preference):

SharePoint Property Bag

This can be used for all the custom SharePoint solutions (Farm, Web Application, Site Collection, Web). The only disadvantage that I found is the fact that you have to build an application page or a web part to manage this items, because there is no interface provided by default.

What I wanted to share in this article were the get/set (load/save) methods that I use to access the Property Bag in my custom solutions. Usually I create a public static class called Helpers, where I store all the common methods needed in a solution. To load and save the Property Bag data I created a LoadProperty and a SaveProperty method with two overloads each.

In case we call this method from a FeatureActivated event, we need the second overload. In this case the object SPContext.Current.Web does not exist. Anyway you can find below the code that I used:

#region Load Configuration Property
public static string LoadProperty(string strKeyName)
{
string strResult = string.Empty;

SPWeb webCurrent = SPContext.Current.Web;

if (webCurrent.Properties.ContainsKey(strKeyName))
{
strResult = webCurrent.Properties[strKeyName].ToString();
}
return strResult;
}

public static string LoadProperty(SPWeb webCurrent, 
string strKeyName)
{
string strResult = string.Empty;

if (webCurrent.Properties.ContainsKey(strKeyName))
{
strResult = webCurrent.Properties[strKeyName].ToString();
}
return strResult;
}
#endregion

A Simple LOB Application in SharePoint: Should I use InfoPath List Forms or the default SharePoint Forms ?

Written by Denis Stadler on . Posted in Custom Development, SharePoint 2010

Everything starts with a simple business requirement: the customer wants a simple ticketing solution. This ticketing solution ought to have the following features:

  • The information kept should be: Title, Description, Comments, Status of the Issue, Due Date, possibility to attach files.
  • The Due Date has to be at least one week from the creation date of the ticket unless the user is not member in a special team which is allowed to brake this rule.
  • The information displayed into the New, Display, Edit has to be different based on the user role. For example when adding a new ticket the Status field should always be New.
  • The is an attached approval workflow mainly based on the status of the ticket: New – Assigned – Working – Waiting for Approval – Approved – Closed.

The first step was to create a new site content type which inherits the built-in Issue content type. I created it at the Site Collection level and this way I got the possibility to use it in every sub-site of the site collection.

The second step was to create the Ticketing list based on the Issue list template and enable content types on it (from Advanced settings). Then I removed the default content type and added my content type as the default content type for this list.

The question was how to implement further. If for the process it was clear that I was going to use a SharePoint Designer Workflow, for the data views (New, Display, Edit) there was a big question: which of the two available options to choose: InfoPath List Forms or SharePoint Default List Forms.

Hiding SharePoint Page Elements Based on the Currently Logged in User

Written by Denis Stadler on . Posted in Custom Development

You may get this business requirement in the one following scenarios:

– You want to exclude part of a page (for example static links in the Master Page) from being indexed by SharePoint Search
– Just hide page elements for a specific user

For the Search scenario in SharePoint 2010 there is the possibility of using a div with CSS class name equal to noindex for not having the content crawled, but this doesn’t work in MOSS 2007.

<div class=”noindex”>content no to be indexed</div>

SharePoint has a build in feature which filters content based on the security roles of the user: SPSecurityTrimmedControl.

But the is no class for content trimming based on the loged-in user account, and we will create it :). The advantage is that this should work both in SharePoint 2010 and MOSS 2007.

Phase 1: Development

The C# class doesn’t contain more than:

public class SPUserSecurityTrimmedControl : SPSecurityTrimmedControl
{

public string ExcludeUser
{
get; set;
}

protected override void Render(HtmlTextWriter output)
{
SPWeb site = SPContext.Current.Web;

if (site.CurrentUser.LoginName.ToLower() != ExcludeUser.Trim().ToLower())
{
base.Render(output);
}}}

How to Create a Sandboxed Web Part and Deploy It to Office 365 / SharePoint 2010

Written by Denis Stadler on . Posted in Custom Development, Office 365, SharePoint 2010

First of all you will need a Development Environment with SharePoint 2010 and Visual Studio 2010.

Download and install SharePoint 2010 SDK.

Download and install Visual Studio 2010 SharePoint Power Tools.

Then you have to enable Microsoft SharePoint Foundation Sandboxed Code Service in Central Administration. Go to Central Administration and then click Manage services on server.