Retrieve Lists in SharePoint 2010 Programmatically Using VS 2010 Via COM


Today, in this article let's play around with one of the interesting and most useful concepts in SharePoint 2010.

Question: What is retrieving lists via COM?

In simple terms "To enable retrieval of all lists in the web using the client object model".

Step 1: Open Visual Studio 2010 and create an "ASP.NET Web Forms Application", as in:

Now two references need to be added to the application, they are:

  • Microsoft.SharePoint.Client

  • Microsoft.SharePoint.Client.Runtime

Step 2: The complete code of webform1.aspx looks like this:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RetrieveListinWebApp._Default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head id="Head1" runat="server">




    <form id="form1" runat="server">



            <table style="text-align: center">


                    <td colspan="2">

                        <asp:Label ID="Label1" runat="server" Text="Client Object Model - Show Lists - SharePoint 2010 Programatically"

                            Font-Bold="true" Font-Size="Large" Font-Names="Verdana" ForeColor="Maroon"></asp:Label>




                    <td colspan="2">

                        <br />

                        <asp:Button ID="Button1" runat="server" Text="Show All Lists" Font-Names="Verdana"

                            Width="282px" BackColor="Orange" Font-Bold="True" OnClick="Button1_Click" />




                    <td colspan="2">

                        <br />

                        <asp:ListBox ID="ListBox1" runat="server" Height="399px" Width="239px"></asp:ListBox>










Step 3: The complete code of webform1.aspx.cs looks like this:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Microsoft.SharePoint.Client;

namespace RetrieveListinWebApp


    public partial class _Default : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)



        protected void Button1_Click(object sender, EventArgs e)


            ClientContext objContext = new ClientContext("http://win-kv3bo1rqqf7:25339/");

            Web objWeb = objContext.Web;

            objContext.Load(objWeb.Lists, alllists => alllists.Include(list => list.Title, list => list.Id));


            foreach (List list in objWeb.Lists)








Step 4: The output of the application looks like this:



Step 5: The lists retrieved output of the application looks like this:



I hope this article is useful for you.

MVC Corporation
MVC Corporation is consulting and IT services based company.