Wednesday, July 17, 2013

Add a Geolocation column to a list programmatically in SharePoint 2013

Here in this article we will discuss about how we can add a Geolocation column to a SharePoint 2013 list using SharePoint 2013 client object model.

SharePoint 2013 Preview introduces a new field type named Geolocation that enables you to annotate SharePoint lists with location information. In columns of type Geolocation, you can enter location information as a pair of latitude and longitude coordinates in decimal degrees or retrieve the coordinates of the user’s current location from the browser if it implements the W3C Geolocation API.

First we need to add the below 2 dlls to work with SharePoint 2013 client object model.

Microsoft.SharePoint.Client.dll

Microsoft.SharePoint.Client.Runtime.dll

Then we need to write the using statement like below:

using Microsoft.SharePoint.Client;

Below is the full code:

ClientContext context = new ClientContext("http://site url"); 

List oList = context.Web.Lists.GetByTitle("MyCustomList");

oList.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Location'/>",true, AddFieldOptions.DefaultValue);                                        

oList.Update();

context.ExecuteQuery();

No comments:

Power Automate + Excel data

Extract excel data, get manager and update row with user details which will get from GET MANAGER Concepts and examples Key column:  Column i...