Search code examples
vb.netlinqsharepointsharepoint-2010sharepoint-list

How to query a Sharepoint 2010 List from Winform Application?


What is the easiest route to query a SharePoint 2010 list from a VB.Net Windows Forms application.


Solution

  • Using the .NET client object model, as documented by Microsoft here, you can write C# or VB.Net code to access SharePoint.

    Microsoft has provided a walkthrough that shows you how to add the required assemblies to your project.

    Here's the relevant excerpt:

    In your project, add references to the two required assemblies that compose the .NET client object model. These two assembles (Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll) are located in the ISAPI folder of %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14.

    Once you have the assemblies loaded, you can use the SharePoint client object model objects to retrieve information as documented here. For example:

    How to retrieve objects

    The following example shows how to load an object to access its properties. Because the list object is loaded in place, all default properties of the list can be accessed.

    Dim clientContext As New ClientContext("http://MyServer/sites/MySiteCollection")
    Dim oWebsite As Web = clientContext.Web
    Dim collList As ListCollection = oWebsite.Lists
    
    Dim oList As List = collList.GetByTitle("Announcements")
    
    clientContext.Load(oList)
    
    clientContext.ExecuteQuery()
    
    Console.WriteLine("Title: {0} Created: {1}", oList.Title, oList.Created)
    

    Refer to the links above for more in-depth documentation.