Just little about C#, .NET, SQL Server, SharePoint and SAP

Archive for March, 2010

SPUtility.Redirect and SPRedirectFlags

Posted by zieglers on March 31, 2010

Here is a nice article on SPUtility.Redirect from Ton Stegeman.

Redirect in SharePoint using SPUtility.Redirect

Specifically, I was trying to understand where to use SPRedirectFlags, and this article shows it along with some examples.


Posted in IT Stuff, SharePoint | Tagged: , , , , | 2 Comments »

Creating custom toolbar menu

Posted by zieglers on March 26, 2010

Recently I was trying to create a custom toolbar menu group for some bulk actions I developed. At first I thought it’d be as easy as creating a <CustomActionGroup> feature. However, as I tried and tried I realized that it was way more complicated than that.

Basically you need to implement abstract ToolBarMenuButton class. You can find implementation details in this thread from SharePoint msdn forum:

How to create custom toolbar menu 


Posted in IT Stuff, SharePoint | Tagged: , , , , , , | 1 Comment »

GeneriX for SharePoint (Refactoring Applied) – Part: 2

Posted by zieglers on March 25, 2010

In this post I’ll mention the refactoring updates I applied today on GeneriX solution. This post is directly related to previous post (GeneriX for SharePoint) and can be considered as an extension of it.

If you remember, we used copy-paste approach to duplicate some class definitions (action and handler classes) in step-1 and step-3 of previous post. Actually, by doing so we kinda implemented new action and handler classes for our new custom action: check-out items.

Simply copy-paste introduces duplicate code, which actually needs to be written only once, if proper refactoring is applied. 

In our case, custom actions and custom handlers were repeating some common rendering and init functions. So I introduced two new base classes for those: CustomActionBase and CustomHandlerBase.

CustomHandlerBase Class:

CustomActionBase Class:

As seen, both classes are declared abstract. Also keyword virtual used for methods which can be overridden in derived classes.

Hopefully this comparison (Virtual vs. Abstract Classes) helps to understand why ProcessItem and SetUIDetails methods are declared as abstract. Because those methods MUST be implemented by deriving classes.

Actually implementation of ProcessItem will be our custom logic that we’d like to apply on each selected item. e.g. delete, check out …etc. 

Similarly, implementation of SetUIDetails will determine UI behaviour of our custom Actions Menu item, such as title, icon, description.

Now, let’s see how simplified our action and handler classes are after refactoring applied.

For instance, below you can see handler and action classes for custom action: Delete. In our handler class, we have no unnecessary code, simply we have just the code we need to process a selected item, which is deleting in this case. Since, ProcessItem method was declared as abstract in base class, we implement it here in deriving class. If you don’t, you get a compilation error during build.

In derived action class, all we need to provide is UI details for our actions menu item. For delete operation, providing details below, assigns necessary values for our delete menu item control.

In summary, it’s a good practice to apply Refactoring on your code where possible. Not only it reduces amount of code you write, but also it improves code execution performance. Also, your code becomes more modular and easy to read and understand by others.

GeneriX Wsp: Zieglers.SharePoint.Generic.20100325.wsp

GeneriX Source Code: GeneriX.zip

(Don’t forget to remove .doc extension Rename downloaded files exactly as seen above)

Let me know if you have questions regarding refactoring, virtual-abstract classes, source code, deployment issues … etc.


Posted in IT Stuff, SharePoint | Tagged: , , , , , , , | 3 Comments »

Virtual vs. Abstract Classes

Posted by zieglers on March 25, 2010

Here is a brief comparison of VIRTUAL and ABSTRACT classes:


The virtual keyword is used to modify a method, property, indexer or event declaration, and allow it to be overridden in a derived class.

The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes. Members marked as abstract, or included in an abstract class, must be implemented by classes that derive from the abstract class.

Abstract classes have the following features:
– An abstract class cannot be instantiated.
– An abstract class may contain abstract methods and accessors.
– It is not possible to modify an abstract class with the sealed (C# Reference) modifier, which means that the class cannot be inherited.
– A non-abstract class derived from an abstract class must include actual implementations of all inherited abstract methods and accessors.

In general, virtual does not work on classes.
It is only for a class method, property, indexer or event declaration to have the possibility, to override them in a derived class.
An abstract class can’t be initiated and can more interpretated as a template of a class, which has to be derived to create an instance of it. 


Posted in .NET Framework, C#, IT Stuff | Tagged: , , , , , | 1 Comment »

GeneriX for SharePoint – Part: 1

Posted by zieglers on March 25, 2010

In this post, I’ll mention about GeneriX solution for SharePoint. In fact, i call it GeneriX since it is developed under namespace SharePoint.Core.Generic.

Point is to include any projects implementing a generic idea in this namespace. For example as for this post, I’ll show ‘Select Multiple List Items’ and ‘Delete Items’ custom action menu item.

 This project consists of two parts:

 1. Select Multiple Items – Adding checkboxes next to items in lists so that user can select and work on more than one list item.

 2. Delete Items – A custom action which simply deletes all items selected by user. This is done by implementing a custom ‘Actions Menu‘ item. However, implementation is done in a way that it can be customized very easily to any other custom action incase needed.

You might ask which part of this solution is generic since i keep using word ‘custom’. It is generic, because two parts of the solution are both individually generic actions – namely being able to select multiple items and deleting multiple items. Moreover, you can easily extend custom actions classes to introduce your own actions (handling multiple items) such as check-out/check-in, approve, publish, approve, alert me … etc.

 DEMO: Here is a short demo of the functionality.

 Upload multiple items in a sample lib (where multiple list item selection is not enabled yet).

Enable multiple list item selection using Actions Menu.

NOTE: By default, once this solution is deployed, multiple item selection is enabled on lists. You don’t need to take below action explicitly. This is just for demonstration.

Select items you want to delete.

Select ‘Delete Items’ in Actions.

Confirm deletion.

Selected items are deleted.

Very simple yet powerful!! 


 Now let’s see how we can extend this generic project to introduce another bulk action to process multiple items.

GeneriX wsp: Zieglers.SharePoint.Generic.20100325.wsp

GeneriX Source Code: GeneriX.zip

(Don’t forget to remove .doc extension 🙂 Rename downloaded files exactly as seen above)

 When you download GeneriX solution and open it, you’ll see the following in Solution Explorer. (Following solution structure might change as development progresses)

Here there are 3 features:

JQuery – supporting infrastructure feature

SelectMultipleListItems – this feature introduces enable/disable multiple items functionality for lists. This feature is making use of JQuery feature as well.

DeleteItems – this feature introduces delete multiple items functionality.

We can think of first 2 features as supporting features for custom action features like delete items.

Now let’s implement another custom action say ‘Check-out Items’ which performs a multiple check-out action on selected items.

Step-1: Implement MenuItemTemplate interface

Simply copy-paste whole DeleteItemsAction class and rename Delete to CheckOut for that class.

Here basically we are creating a new Actions Menu item for Check-out operation.

Now, our custom action class is ready for CheckOut operation.

Step-2: Create a ashx file for CheckOut items

This is a handler file to determine which handler code to execute once user clicks on our CheckOut items actions menu item.

In order to do so, simply copy-paste DeleteItems.ashx file residing under layouts folder and rename it to CheckOutItems.ashx.

Open the file and also rename DeleteItemsHandler to CheckOutItemsHandler.

By doing so, we basically state which handler class to be executed once user clicks ‘Checkout Items’. In next step, we’ll implement CheckOutItemsHandler class.

Step-3: Implement CheckOutItemsHandler class

So far, we created a menuitemtemplate for checkout items and a handler file to point which handler class to execute. This handler class will implement our custom logic (whatever your business logic might be) in this case, check-out items.

Similar to above, open CustomActionHandlers.cs and copy-paste DeleteItemsHandler class and again rename Delete to CheckOut.

Note that this class is implementing IHttpHandler interface which basically is catching user http request upon clicking CheckOut Items menu item.

Step-4: Write your code implementing your custom logic

We are almost done. Search for ‘Write Your Code’ in the new class you created and simply include your code snippet there.

 In our case, it is Check-Out action, so all i need to do is just include only one line code as seen below.

Well, that’s all about it. We are done! 🙂

Now build, deploy and test your changes..

Let me know if you run into any issues. I’ll be glad to help.


Posted in IT Stuff, SharePoint | Tagged: , , , , , , , , , | 1 Comment »

Toronto SharePoint Camp 2010 on March 20th

Posted by zieglers on March 4, 2010

Annual SharePoint event which will be held on March 20th this year. It’s free and everyone is welcome. You can register using the following link.


I’ll also present a session there on Custom Expiration Policy.

Hope to see you there!!!


Posted in IT Stuff, SharePoint | Tagged: , , | Leave a Comment »