Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting the Exception:

    WebException was unhandled:
    An unhandled exception of type 'System.Net.WebException' occurred in 
    Microsoft.SharePoint.Client.dll

   Additional information: The remote server returned an error: (401) 
 Unauthorized.
However, I can access the site using the same credentials in the browser. Please note that I am using username "username@companyname.com" and my username also includes a dot in it. I am afraid whether something is wrong with my username but I can access my site using the exactly same username. Any help will be highly appreciated. Thanks in advance.


What I have tried:

I am trying to read files from Sharepoint. I have used the following codes:

using System;
using Microsoft.SharePoint.Client;
using System.Security;

  namespace VLCPlayer
{
public partial class Form1 : System.Windows.Forms.Form
{
    public Form1()
    {
        InitializeComponent();
        string url = "https://share.philips.com/sites/STS020170405131503/";
        ClientContext ctx = new ClientContext(url);
        var password = new SecureString();
        foreach (var c in "passwor".ToCharArray()) 
        { password.AppendChar(c); }
        ctx.Credentials =
           new SharePointOnlineCredentials(username, password);

        Microsoft.SharePoint.Client.Web web = ctx.Web;

        ctx.Load(web);

        ctx.ExecuteQuery();

        Console.WriteLine(web.Title);
      }
    }
}
Posted
Updated 8-Jun-17 8:56am

1 solution

perhaps a type but "passwor" should be password.To....
No quotes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900