SyntaxHighlighter

Tuesday, April 29, 2014

How to disable event firing in custom code


Recently I worked on application page which updates list item, which in turn causes item update event to fire. The goal was to avoid any event execution. I have done this many times before, but had a hard time recalling. This post is a note to myself, so I know where to look for code sample, if I forgot again. :)

If I am writing event receiver, I can use EventFiringEnabled property to disable events temporarily. But in application page I don’t’ have access to SPEventReceiverBase
which exposes this property. So here is the coed I used to temporarily disable event firing.

public class DisableItemEventFiring : SPItemEventReceiver, IDisposable 
{
public ItemEventFiring()
{
this.EventFiringEnabled = false;
}

public void  Dispose()
{
this.EventFiringEnabled = true;
}
}


Now we have defined class for disabling list item event, I can use this class in application page,

using (DisableItemEventFiring disableEvt = new DisableItemEventFiring ())
{
//no event will be fired
item.SystemUpdate();
}

//event firing enabled again
item.SystemUpdate();


Hope this helps.

-Javed

Wednesday, April 2, 2014

JavaScript Frameworks


With arrival of SharePoint 2013 last year and Microsoft push to move your code away from SharePoint server to the client browsers, JavaScript is now considered an important skill. The new SharePoint App model allows developers to use JavaScript to write entire application and in case of SharePoint-hosted app, is the only option. Now it is a good idea to spend some time understanding and learning JavaScript and many freely available Frameworks. If you are writing Single Page Application or just DOM manipulation or implementing user notifications, there are at least couple of open source JavaScript frameworks available. I have been using some of these and below is the list of some of those frameworks.

jQuery I think the most popular and useful library.
AngularJS Recently completed Single Page App on SharePoint using Angular and I love this framework for its powerful bi-directional data binding, routing, REST support and much more.
Knockout.js Great bi-directional data binding framework, but the only thing bothers me is to convert JSON (from server) to observable collection.
Underscore.js Makes life lot easier handling arrays and collection
moment.js Date and time utility functions. Data validation, formatting, international formatting.
noty.js A jQuery plugin to display success/error notification. Highly configurable.
toastr.js Similar to noty.js
Open XML SDK for JavaScript Now you can create Office documents right in the browser with this library. Check out these links for more info:
Introducing the Open XML SDK for JavaScript
Open XML SDK for JavaScript

I will continue adding more libraries and frameworks as and when I get a chance to play with.

Hope this helps.

-Javed