In this post, we will discuss how to retrieve all the available lists in Windows form in SharePoint 2010.
New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features
Also, you can check out:
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
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
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
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.
using (ClientOM.ClientContext ctx = new ClientOM.ClientContext(textBox1.Text))
ClientOM.Web site = ctx.Web;
ctx.Load(site, x => x.Lists.Where(l => l.Title != null));
foreach (ClientOM.List list in site.Lists)
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.
FREE SHAREPOINT 2019 PDF
(Installation & Features)