Howto: Use lambda expression in SharePoint – Working with SPWeb
English
Before you continue reading this post, I hope you have read the basic task to start using lambda expression in SOM here.
A. Find any Event list in site.
SPWeb spWeb = SPContext.Current.Web
var lists = spWeb.Lists.OfType<SPList>().Where(
l => l.BaseTemplate == SPListTemplateType.Events);
foreach (SPList list in lists)
{
Console.WriteLine("{0} {1}", list.BaseTemplate.ToString(), list.Title);}
B. Find any list based on custom list definition with Type=20080
SPWeb spWeb = SPContext.Current.Web
var lists = spWeb.Lists.OfType<SPList>().Where(
l => (int) l.BaseTemplate == 20080);
foreach (SPList list in lists)
{
Console.WriteLine("{0} {1}", list.BaseTemplate.ToString(), list.Title);}
C. Find any “Daily” alert in the site
SPWeb spWeb = SPContext.Current.Web
var alerts = spWeb.Alerts.OfType<SPAlert>().Where(
a => a.AlertFrequency == SPAlertFrequency.Daily);foreach (SPAler alert in alerts)
{
// Do something with alert}
D. Find any user which are Domain group
SPWeb spWeb = SPContext.Current.Web
var users = spWeb.SiteUsers.OfType<SPUser>().Where(
u => u.IsDomainGroup );foreach (SPUser user in users)
{
// Do something with alert}
December 3rd, 2009 at 9:44 pm
[...] ran into a very nice article about using Lambda’s/LINQ on SharePoint objects. You can find it here. Categories: LINQ, Lambda, SharePoint Tags: Lambda, LINQ, SharePoint Comments (0) [...]
December 21st, 2009 at 4:54 pm
In this case, you can use Cast() instead of OfType() for better performance.
February 17th, 2010 at 3:28 pm
Good work!
http://www.xavor.com/whatwedo/solutions/sharepointmigrationtool.aspx