I am using visual studio 2015......I need to connect to sharepoint through visual stuido.
I added microsoft sharepoint online csom reference in vs 2015
but i unable to execute the code due to error.....
I am using visual studio 2015......I need to connect to sharepoint through visual stuido.
I added microsoft sharepoint online csom reference in vs 2015
but i unable to execute the code due to error.....
If you are using SharePoint Online, please use SharePointOnlineCredentials class to set credentials to ClientContext object, here is a code snippet for your reference:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.SharePoint.Client;
namespace CSOMWinApp
{
public partial class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string password = "xxxxxx";
string account = "user@Tenant.onmicrosoft.com";
var secret = new System.Security.SecureString();
foreach (char c in password)
{
secret.AppendChar(c);
}
var credentials = new SharePointOnlineCredentials(account, secret);
using (ClientContext ctx = new ClientContext("https://zheguo.sharepoint.com/sites/dev"))
{
ctx.Credentials = new SharePointOnlineCredentials(account, secret);
Web web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
}
}
}
}
Reference: