.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Fetching lists from SharePoint 2010 site using client object model

Posted By:Dhananjay Kumar       Posted Date: January 30, 2011    Points: 75    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article we will see how we can Fetch lists from SharePoint 2010 site using client object model.
 

Fetching lists from SharePoint 2010 site using client object model. You can also follow my Blog

Creating the UI

1.  Add a label
2.  Add a textbox. Give any meaningful name I am leaving default name here.
3.  A button. On click event of the button list names will be fetched.
4.  A listbox control to bind the lists from SharePoint site.

Setting up the environment


Right click on the project .Click on the Application tab and change the Target framework type to .Net Framework 3.5



Add the references of below dll in the project.

Microsoft.SharePont.Client 
Microsoft.SharePoint.Client.Runtime



After adding the dll, add below namespace



Now on the click event of btnGetLists write the below code

Code to Retrieve the Lists of SharePoint site

On click event of the button, write the below code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
 
using SharePointclientObj = Microsoft.SharePoint.Client;
 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void btnGetLists_Click(object sender, EventArgs e)
        {
             listBox1.Items.Clear();
            //Get a context
             using (SharePointclientObj.ClientContext ctx = new SharePointclientObj.ClientContext(textBox1.Text))
             {
                 //Get the site
                 SharePointclientObj.Web site = ctx.Web;
                 ctx.Load(site);
                 //Get Lists
                 ctx.Load(site.Lists);
                 //Query
                 ctx.ExecuteQuery();
                 //Fill List
                 foreach (SharePointclientObj.List list in site.Lists)
                 {
                     listBox1.Items.Add(list.Title);
                 }
 
             }
        }
    }
}

Output



 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend