I try to connect a sharepoint list using SharePoint 365.
For manual access, the browser is opening connecting to
https://login.microsoftonline.com
and I have to Sign In
using my Email-Address - no password is needed. Looks like this:
Now, I want to access a sharepoint list via Microsoft.Sharepoint.Client.dll
and generated this code for a first try:
public static class Program
{
public static System.Uri SPLink = new System.Uri("https://ListToSharepoint.com/sites/Topic/Lists/ListName/AllItems.aspx");
static void Main(string[] args)
{
Microsoft.SharePoint.Client.ClientContext Cc = new Microsoft.SharePoint.Client.ClientContext(SPLink);
System.Security.SecureString MyPassword = new System.Security.SecureString();
foreach(char c in "AtWebLoginThereIsNoPasswordNeeded") { MyPassword.AppendChar(c); } /*If I comment this line, the same error occures*/
Cc.Credentials = new Microsoft.SharePoint.Client.SharePointOnlineCredentials("ImUsing.ThisEmail@ForLogin.com", MyPassword);
Microsoft.SharePoint.Client.List MyList = Cc.Web.Lists.GetByTitle("ListName");
Microsoft.SharePoint.Client.ListItemCollection LIC = MyList.GetItems(new Microsoft.SharePoint.Client.CamlQuery());
Cc.Load(LIC);
Cc.ExecuteQuery(); /*System.Net.WebException: 'Der Remoteserver hat einen Fehler zurückgegeben: (401) Nicht autorisiert.'*/
return;
}
}
Executing the code, I get a System.Net.WebException: Not autorized
Does anybody knows some help for me? Using the System.Net.CredentialCache.DefaultCredentials
or System.Net.CredentialCache.DefaultNetworkCredentials
also results in the same error.
Links, Username and Password are fake in this posting...
Thanks and regards, Jan