Using Lamba expression to process SharePoint objects (or any data you need to process)

This is just a trick to make your life easier. You can use this against any data in SharePoint as long as you do not need performance critical functionality. Remember that doing lambda expressions against big objects such as get an SPWeb or going through a list of SPWeb is still going to cost you the memory allocation and CPU utilization.

Sample how to remove an event receiver from a list:

using System.Linq;

var eventReceiver = list.EventReceivers.Cast<SPEventReceiverDefinition>().SingleOrDefault(o => o.Class.ToLower().Contains(receiverClass.ToLower()));
if (eventReceiver != null)
var allowUnsafeUpdates = web.AllowUnsafeUpdates;
web.AllowUnsafeUpdates = true;

web.AllowUnsafeUpdates = allowUnsafeUpdates;

Remember the concepts Late binding, Delayed Execution and Captured Variables.

Check you this Explanation from StackOverflow =>

Late-binding: This is where the meaning of code is determined after it was compiled. For example, x.DoStuff() is early-bound if the compiler checks that objects of x‘s type have a DoStuff() method (considering extension methods and default arguments too) and then produces the call to it in the code it outputs, or fails with a compiler error otherwise. It is late-bound if the search for the DoStuff() method is done at run-time and throws a run-time exception if there was no DoStuff() method. There are pros and cons to each, and C# is normally early-bound but has support for late-binding (most simply through dynamic but the more convoluted approaches involving reflection also count).

Delayed execution: Strictly speaking, all Linq methods immediately produce a result. However, that result is an object which stores a reference to an enumerable object (often the result of the previous Linq method) which it will process in an appropriate manner when it is itself enumerated. For example, we can write our own Take method as:

private static IEnumerable<T> TakeHelper<T>(IEnumerable<T> source, int number)
  foreach(T item in source)
    yield return item;
    if(--number == 0)
      yield break;
public static IEnumerable<T> Take<T>(this IEnumerable<T> source, int number)
  if(source == null)
    throw new ArgumentNullException();
  if(number < 0)
    throw new ArgumentOutOfRangeException();
  if(number == 0)
    return Enumerable.Empty<T>();
  return TakeHelper(source, number);

Now, when we use it:

var taken4 = someEnumerable.Take(4);//taken4 has a value, so we've already done
                                    //something. If it was going to throw
                                    //an argument exception it would have done so
                                    //by now.

var firstTaken = taken4.First();//only now does the object in taken4
                                        //do the further processing that iterates
                                        //through someEnumerable.

Captured variables: Normally when we make use of a variable, we make use of how its current state:

int i = 2;
string s = "abc";
i = 3;
s = "xyz";

It’s pretty intuitive that this prints 2 and abc and not 3 and xyz. In anonymous functions and lambda expressions though, when we make use of a variable we are “capturing” it as a variable, and so we will end up using the value it has when the delegate is invoked:

int i = 2;
string s = "abc";
Action λ = () =>
i = 3;
s = "xyz";

Creating the λ doesn’t use the values of i and s, but creates a set of instructions as to what to do with i and s when λ is invoked. Only when that happens are the values of i and s used.

Putting it all together: In none of your cases do you have any late-binding. That is irrelevant to your question.

In both you have delayed execution. Both the call to Take and the call to Where return enumerable objects which will act upon arr when they are enumerated.

In only one do you have a captured variable. The call to Take passes an integer directly to Take and Take makes use of that value. The call to Where passes a Func<int, bool> created from a lambda expression, and that lambda expression captures an int variable. Where knows nothing of this capture, but the Func does.

That’s the reason the two behave so differently in how they treat cutoff. ”


Microsoft sources of info:

Lambda Expressions (C# Programming Guide)

Getting Started with LINQ in C#

101 LINQ Samples

VMWare Client NAT Internet Access not working – Error: Media disconnected

Annoying problem with WMWare. If you happen to use NAT to share your host internet connection to your client image you may encounter this problem. If you open on a windows machine command prompt and type ipconfig you might get errors stating something in the line of “Media disconnected”. To fix this problem you can retore your VMWare NAT settings. Go to your VMWare tool bar => Edit => Virtual Network Editor. In the editor chose from the networks list the network with the type “NAT”, then press “Restore Default” button in lower left corner. Let VMWare do its magic. Notice that your virtual machines need to be closed.

vmware network problem


SharePoint Search Service Application Errors: The search application ‘Search Service Application’ on server did not finish loading. View the event logs on the affected server for more information

If you get this (annoying) error then a possible solution is to check if your account which you use to administrate(or use the search service application) on the SQL Server side.

The search application ‘Search Service Application’ on server did not finish loading. View the event logs on the affected server for more information

Open Your SQL Server Management studio. Go to your Security folder, then Logins and then double click on your account which needs search privileges. Then go to user mapping in the new window and check that the following search service databases has privileges to your account and that the account has the “SPSearchDBAdmin” rights assigned:

Search Databases:





Search Service Application Error

Search Service Application Error

SharePoint solution package installation fails when activating feature that updates fields

If you happen to get the following errors related to site columns, features activation and/or solution package installation:

Unable to locate the xml-definition for FieldName with FieldId ‘Your field GUID’, exception: Microsoft.SharePoint.SPException —> System.Runtime.InteropServices.COMException: <nativehr>0x8000ffff</nativehr><nativestack></nativestack>
at Microsoft.SharePoint.Library.SPRequestInternalClass.GetGlobalContentTypeXml(String bstrUrl, Int32 type, UInt32 lcid, Object varIdBytes)
at Microsoft.SharePoint.Library.SPRequest.GetGlobalContentTypeXml(String bstrUrl, Int32 type, UInt32 lcid, Object varIdBytes)

Or Error message:

Field not found or invalid – ID: [your field GUID]

Then you have two options:

  1. Set the field attributes ‘Overwrite‘ and/or ‘OverwriteInChildScopes‘ to True =>
  2. Or if this does not help then what will kill your Microsoft support for you SharePoint installation is to modify the database directly(not recommended BUT if it is not a production environment and for some reason you need to do something quick and dirty to test something then this might be an option) =>


Apple’s Swift language not ready for production use?

I’ve been playing around with Swift for a few months now and have been happy with the language and making applications with it BUT there where problems, bugs and annoying crashes while developing with Swift and XCode. During the Beta phases this was OK but now that the XCode 6.0 is out as non Beta some of the same bugs still exists and for me two bugs are the most annoying and a show stopper which keeps me from not using Swift with iOS development up until Swift and XCode matures and the bugs are Fixed.

The two most annoying bugs are:

  • XCode “intellisense” and indexing crashing once application and code complexity evolves
  • Swift compiler bugs where you are forced to clean your development environment or create a new development environment from scratch because XCode and Swift compiler refuse to compile your code citing to illogical errors that are not there. This was a big show stopper since the code had no syntax errors and would compile on another Mac OS development image.

Long story short once my application grew in size, functionality and complexity Swift and XCode started to fall apart forcing me to state that I have to move to other languages and frameworks to do what I need to do for the application to work. As a developer nothing is more annoying than tools that do not work and make you use hours upon hours to fix or go around the issues.

Others seem to feel the same way:


It’s a shame, Swift looks promising but for now it is best to stay away in anything else than small projects and testing of new functionality.

SharePoint Content Editor WebPart PostBack problems

This fix is for when you are trying to add content to the editor web part when it is empty and causes a post back failing to added any content. Add this Jquery line to your JS file and the problem will go away. The problem is Microsoft SharePoint JavaScript that should replace the “add content” text in the editor webpart and the anchor href. By removing the href attribute fromt he anchor the MS JS will still work and the problem will go away: