Retrieve available lists in Windows Form for SharePoint 2010

InfoPath alternatives for form designing SharePoint

In this post, we will discuss how to retrieve all the available lists in Windows form in SharePoint 2010.

Also, you can check out:

Assign Manager to user from active directory to SharePoint 2010

Hide a column from List Form(new/edit/display) in SharePoint Server 2010

Remove Extended Zone using PowerShell in SharePoint 2013

Step-1: Designing the Windows Form interface

1. Open the Visual Studio and create the new project.

2. On the Start page, in the Projects section, click New Project.

3. In the Installed Templates section, in the Visual C# group, click Windows, and then click Windows Forms Application.

4. Ensure that the .NET Framework version has been set to 3.5. See in fig

 Retrieve available lists in Windows Form for SharePoint 2010
Retrieve available lists in Windows Form for SharePoint 2010

5. Give the name of your windows application form and give the location.

6. Click OK.

7. In the Solution Explorer window, right-click and then click Add Reference.

8. Click the Browse tab, and then browse to the following location:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI.

9. Click Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll. See in fig

 Retrieve available lists in Windows Form for SharePoint 2013
Retrieve available lists in Windows Form for SharePoint 2013

10. Click OK. Now the references are added to the Solution Explorer window under References.

11. Click the Toolbox to the left of the editor pane and click the pin icon.

12. Expand Common Controls, then click and drag a TextBox control onto Form1. This control will be used to enter a web address.

13. Click the Toolbox to the left of the editor pane and expand Common Controls, then click and drag a ListBox control onto Form1. Place the ListBox below the TextBox you have already added. This control will show lists available in the site specified in the TextBox.

14. Click the Toolbox to the left of the editor pane and expand Common Controls, then click and drag a Button control onto Form1.

15. In the right-hand properties, window changes the Text property from Button1 to Show Lists.

16. Your form should look similar to the following example: See in fig

 Retrieve available lists in Windows Form for SharePoint 2016
Retrieve available lists in Windows Form for SharePoint 2016

Step-2: Adding code to the Windows Form application

In this task, you will add code to the Windows Form Application. You will add code for the button control.

1. Double-click the Button control to open the code window.

2. Enter the following namespace.

using ClientOM = Microsoft.SharePoint.Client;

3. Add the following code between the braces in the button1_Click event.

listBox1.Items.Clear();

using (ClientOM.ClientContext ctx = new ClientOM.ClientContext(textBox1.Text))

{

ClientOM.Web site = ctx.Web;

ctx.Load(site);

ctx.Load(site.Lists);

ctx.Load(site, x => x.Lists.Where(l => l.Title != null));

ctx.ExecuteQuery();

foreach (ClientOM.List list in site.Lists)

{

listBox1.Items.Add(list.Title);

}

}


4. Press [CTRL] + [F5]. The application builds and the form appears.

5. In the TextBox control, type URL and then press the Show Lists button. Now you See the whole list in that URL. Show in fig.

 Retrieve available lists in Windows Form for SharePoint 2019
Retrieve available lists in Windows Form for SharePoint 2019

You May Also like the Following SharePoint Online Tutorials:

About Navneet Singh

I am Navneet Singh, Working at C3it software solutions pvt. ltd. in Pune. My core skills are SharePoint 2013, Office 365, SharePoint 2010, SharePoint Designer, SharePoint Designer Workflow, Nintex Workflow, Infopath, Webpart, CSOM/SSOM, Power-shell, C#, ASP.NET and SQL Server.

View all posts by Navneet Singh →

Leave a Reply