Remote Authentication in SharePoint Online Using the Client Object Model

This sample demonstrates how to authenticate against Microsoft SharePoint Online in client applications using the managed SharePoint client-side object models.

C# (50.9 KB)
 
 
 
 
 
(12)
8,608 times
Add To Favorites
4/28/2011
E-mail Twitter del.icio.us Digg Facebook
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using System.Net;
using MSDN.Samples.ClaimsAuth;

namespace Sp_Ctx
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            if (args.Length < 1) { Console.WriteLine("SP_Ctx <url>"); return; }

            string targetSite = args[0];
            using (ClientContext ctx = ClaimClientContext.GetAuthenticatedContext(targetSite))
            {
                if (ctx != null)
                {
                    ctx.Load(ctx.Web); // Query for Web
                    ctx.ExecuteQuery(); // Execute
                    Console.WriteLine(ctx.Web.Title);
                }
            }
            Console.ReadLine();
        }
    }
}