Ideas for Free

Ideas for Free

only freedom gives SharePoint real power to grow

Ideas for Free RSS Feed
 

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

  }

3 Responses to “Howto: Use lambda expression in SharePoint – Working with SPWeb”

  1. 1
    LINQ/Lamba and SharePoint « In Development:

    [...] 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) [...]

  2. 2
    denni:

    In this case, you can use Cast() instead of OfType() for better performance.

  3. 3
    rfarqleet:

    Good work!
    http://www.xavor.com/whatwedo/solutions/sharepointmigrationtool.aspx

Leave a Reply

Computers Business Directory - BTS Local