Tuesday, September 8, 2015

SharePoint 2013 Add a Geolocation column to a list programmatically

//SharePoint 2013 Add a Geolocation column to a list programmatically
//To set the Bing Maps key at the farm level using Windows PowerShell
1.       Log on to the SharePoint server as an administrator, and open the SharePoint 2013 Management Shell.
2.       Execute the following command:
Set-SPBingMapsKey –BingKey “ApJ8q265TyIbIz7TpAlxw2oYAf84LmS0a5Z24KT141LL8728c3X1d-aJqQWfpBD9"

//To set the Bing Maps key at the farm or web level using the client object model
//CONSOL Application
using Microsoft.SharePoint.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SetBingMapsKey();           
            ReadBingMapKeu();
        }
        private static void ReadBingMapKeu()
        {
            ClientContext context = new ClientContext("http://SPServer:6677/");
            Web web = context.Web;
            context.Load(web.AllProperties);
            context.ExecuteQuery();
            Console.WriteLine(web.AllProperties["BING_MAPS_KEY"].ToString());
            Console.ReadKey();
        }
        static private void SetBingMapsKey()
        {
            ClientContext context = new ClientContext("http://SPServer:6677/");
            Web web = context.Web;
            web.AllProperties["BING_MAPS_KEY"] = " ApJ8q265TyIbIz7TpAlxw2oYAf84LmS0a5Z24KT141LL8728c3X1d-aJqQWfpBD9";
            web.Update();
            context.ExecuteQuery();
            Console.WriteLine("Bing Maps set successfully");
        }
    }
}
Output:-
//SharePoint 2013: Add a Geolocation column to a list programmatically
//CONSOL Application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint; 
namespace AddGeolocationFieldSample
{
    class Program
    {
        static void Main(string[] args)
        {
            AddGeolocationField();
        }
        private static void AddGeolocationField()
        {
            ClientContext context = new ClientContext(@"http://SPServer:6677/");
            List oList = context.Web.Lists.GetByTitle("Test");
            oList.Fields.AddFieldAsXml("<Field Type='Geolocation' DisplayName='Location'/>", true, AddFieldOptions.AddToAllContentTypes);
            oList.Update();
            context.ExecuteQuery();
            Console.WriteLine("Geolocation field added successfully!");
            Console.ReadKey();
        }
    }
}
Output:-

Reference:-

2 comments:

Featured Post

Develop Azure AI services applications securely by using Azure Key Vault and Run Text Analytics (C#)

//Develop Azure AI services applications securely by using Azure Key Vault and Run Text Analytics (C#) //Create an Azure AI services account...

Popular posts