Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Remote Connection to SharePoint Online site using CSOM

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 527
    Comment on it

    When you want to connect SharePoint Online remote site using CSOM, ClientContext object to be initialized with the Web URL.

    The new SharePointOnlineCredentials class has been introduced by CSOM for SharePoint 2013 which provides this functionality.

    // Namespaces
    using System;
    using System.Security;
    using Microsoft.SharePoint.Client;
    
    // String Variable to store the siteURL
    string webUrl = "http://target.sharepoint.com";
    // String Variable to store the user name
    string userName = "name@tenant.onmicrosoft.com";
    // String Variable to store the password
    string password = "xxxxxxxxxx";
    
    SecureString securePassword = new SecureString();
    foreach (char ch in password)
      securePassword.AppendChar(ch);
    
    
    using (ClientContext context = new ClientContext(webUrl))
    {
      context.Credentials = new SharePointOnlineCredentials(userName,password);
      // To retrieve the web's title.
      context.Load(context.Web, w => w.Title);
      // Execute the query to the server.
      context.ExecuteQuery();
    }

     

    Supply the URL, username, and password of a user that has permission to access the site using CSOM.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: