All posts by Ayman El-Hattab [MVP]

Ayman El-Hattab is a Technology Evangelist @ Nintex & a recognized industry expert focusing on helping organizations plan, design, develop, build, govern and operate enterprise collaboration solutions. You can follow Ayman on Twitter @AymanElHattab to stay updated on his upcoming activities.

Using Lambda Expressions with RunWithElevatedPrivileges

Elevation of privilege, a feature that was added in WSS 3.0 & MOSS 2007, enables you to programmatically perform actions in code by using an increased level of privilege. The SPSecurity.RunWithElevatedPrivilegesmethod enables you to supply a delegate that runs a subset of code in the context of an account with higher privileges than the current user.

For some reason, I have never seen a code snippet that uses a lambda expression instead of the anonymous method syntax so I thought of showing you how to save some typing by using Lambda.

Commonly used syntax:

SPSecurity.RunWithElevatedPrivileges(delegate()
{     // Do things by assuming the permission of the "system account".
});

 

Much easier syntax:

SPSecurity.RunWithElevatedPrivileges(()=>
{     // Do things by assuming the permission of the "system account".
});

When I asked the following question on Twitter : “Why do people still use the anonymous method syntax rather than Lambda Expressions with SPSecurity.RunWithElevatedPrivileges() ? #SharePoint”

I got the following answer from Todd Bleeker : “Delegate syntax has been around a lot longer. Lambda is still confusing and even scary for most. <Todd />”

I totally agree with Todd, but guys if you are not comfortable with LINQ and lambda expressions, you should familiarize yourself with them before diving deep into developing SharePoint 2010 solutions.

As you all might know, Now in SharePoint 2010 you can use LINQ syntax to retrieve items from your lists instead of using CAML queries. Microsoft has included a LINQ provider for SharePoint in the Microsoft.SharePoint.Linq namespace, some classes in this namespace are responsible for translating the LINQ Queries to CAML ones which are eventually translated into SQL. You can still write CAML Queries and fetch items in the old ways but LINQ can really make your life easier specially when it comes to joins.

SharePoint 2010 Community Launch in Photos

Last Wednesday, May 12th was a special day. We had fun celebrating the Egyptian community launch of SharePoint 2010 and Office 2010. I have presented about “Visual Studio Tools for SharePoint 2010”, people were really excited to learn that they no longer need third-party tools for developing SharePoint Solutions. Finally Visual Studio 2010 is enough along with its great extensibility features!

I would like to extend a special thank-you to AvePoint and USPJA for sponsoring the event.

Here are some photos from the event:

13 14  13

16

 

 

USPJ Academy Launch May 17

<Cross Post from USPJA web site>

We are just about ready with the initial parts of the USPJ Academy platform. As such, on May 17, we’re launching the first features of the platform and invite students who have received and accepted a seat in the early access program to join us to begin learning SharePoint.

The first features launched are the library, the forums, and the faculty blog. These features are vital to understanding initial user needs for USPJA and will provide a rich environment in which students can prepare for their upcoming classes.

The official inauguration event happens on May 31, and classes begin on June 1.

</ Cross Post from USPJA Web Site >

For more information about USPJ Academy, see what SharePoint Tech Report wrote about it in April’s newsletter :

11

Drop by “Ask the Experts Panel” at SharePoint 2010 official launch by Microsoft Egypt

Tomorrow May 11th will be an interesting day, Microsoft will be hosting a launch event for Microsoft® Office 2010, Microsoft® SharePoint® 2010, Microsoft® SQL Server® 2008 R2 and Microsoft® Visual Studio® 2010 at Grand Hyatt Hotel – Laylaty Ballroom Time: 09:00 am – 05:00 pm

I will be there in the Ask the experts with my fellow SharePoint MVPs , Marwan Tarek and Shady Khorshied. If you have any SharePoint related questions, please drop by.

SharePoint 2010 Egyptian Community Launch: Transportation Updates

Since the announcement of the Egyptian SharePoint community launch, I have been receiving a lot of emails about the transportation details. Sorry for the delay, but we finally managed to get everything set.

There will be a pickup bus from Lebanon Square.
2:00 to 2:15 > Gathering in-front of Mo’men
2:15 to 3:15 > Moving to Microsoft Egypt
7:45 to 8:00 > gathering in-front of Microsoft
8:00 to 8:45 > back to Lebanon Square

Please if you have any problem regarding transportation, don’t hesitate to call Shady Khorshied on 010 19 11 216 .

I would like also to announce that AvePoint is sponsoring the event, stay tuned to their giveaways 😉

LINQ is Better Than ForEach

5/5/2010

LINQ is Better Than ForEach

Chris Eargle has done a great job comparing LINQ and ForEach loops from the performance and maintainability perspective.

Here is Chris’ conclusion: The vast majority of code I come across that either can be written in LINQ or refactored to LINQ has no noticeable, negative performance impact, but it has a positive impact on maintainability.

Click here to read the full post !

Test your LINQ knowledge

Yesterday, I stumbled upon LINQ Quiz, try to answer as much as you can from the 17 questions posted there, this will help you evaluate and test your LINQ knowledge.

Oh, and before you start writing LINQ queries against your SharePoint lists, you should take a look at this tool (LINQPad), I found it very useful to refresh my LINQ knowledge before diving deep into LINQ to SharePoint. Let me know what you think about LINQPad, I really love it!

My Speaking Schedule For May 2010

It seems that May 2010 will be an interesting month for me, I’ll be busy presenting 3 different SharePoint topics for different user groups and events. The sessions will be in 2 different languages for different audience and nationalities. Two of them will be online and the other will be offline. Below is my speaking schedule in Cairo local time (GMT+3)

Date/Time Topic User Group/ Event Language
SAT May, 1st – 12:00 AM SharePoint 2010 Workflows Online : EgyGeeks Online User Group Arabic
SAT MAY, 8th – 13:30 PM Troubleshooting SharePoint Solutions Online: SharePoint Saturday India English
WED May, 12th – 15:45 PM Visual Studio Tools for SharePoint 2010 Offline: SharePoint 2010 Community Launch by EGYSUG Arabic

Unlocking the Mysteries of the SharePoint Data View Web Part XSL Tags eBook Now Available

Marc Anderson, one of the faculty members of USPJ Academy announced a couple of days ago the availability of a new SharePoint eBook named “Unlocking the Mysteries of the SharePoint Data View Web Part XSL Tags”.

The eBook is based on Marc’s  popular set of articles on EndUserSharePoint.com and his blog. I really enjoyed the Marc’s series and just thought of spreading the word about this valuable eBook which can help you to understand the inner workings of the XSL used in SharePoint’s Data View Web Parts (DVWPs), AKA, the Swiss Army Knife of SharePoint.

Click here to get the eBook.