Query with OData in SharePoint 2013


OData, i.e. Open Data Protocol, which defines a protocol for the querying and updating of data

OData is a REST-based protocol for querying and updating data and is built on standardized technologies such as HTTP, Atom/XML, and JSON.
Microsoft Visual Studio and .NET provide established support for services compliant with the OData specification.
Create a console application in VS 2013.




Right click on project and add service reference.




Enter service url and click on Go, then click on OK



 


Write below code:

    class Program
    {
        static void Main(string[] args)
        {
            ServiceReference1.SharePointCafe2DataContext dcontext = new ServiceReference1.SharePointCafe2DataContext(new Uri("http://win:1002/_vti_bin/listdata.svc"));
            dcontext.Credentials = System.Net.CredentialCache.DefaultCredentials;

            foreach(var item in dcontext.Products)
            {
                Console.WriteLine(item.ItemName);
            }
        }
    }


In above code  Products is a SharePoint list.

Comments

Popular

SharePoint Interview Questions and Answers

Calling ASP.Net WebMethod using jQuery AJAX

What is Cloud Computing - A guide for beginners