3

I want to access some lists to write data into them from a Windows client (or a service).

I tried the following:

using (ClientContext context = new ClientContext("https://myhost.sharepoint.com/"))
{
    context.Credentials = new NetworkCredential("MyUserName@domain.com", "SuperSecretPassword");
    Site site = context.Site;
    context.ExecuteQuery();
}

The result is a 403 error that suggests I am not allowed to perform such requests.

How is it possible to write, update or delete some data in lists in SharePoint Online (aka Office Cloud / Office 365)?

1 Answer 1

3

Use the SharePointOlineCredentials to access your O365 tenant. See example below:

var targetSite = new Uri("https://Your_O365_URL>");
 var login = "<user@tenant>.onmicrosoft.com";
 var password = "<password>";
 var securePassword = new SecureString();
 foreach (char c in password)
 {
 securePassword.AppendChar(c);
 }

var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);

using (ClientContext clientContext = new ClientContext(targetSite))
 {
 clientContext.Credentials = onlineCredentials;
 Web web = clientContext.Web;
 clientContext.Load(web,
 webSite => webSite.Title);

clientContext.ExecuteQuery();
 Console.WriteLine(web.Title);

Console.Read();

 }
2
  • Thx works like a charm! :)
    – Sascha
    May 26, 2014 at 14:55
  • Glad it helped! May 26, 2014 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.