C# Windows Application SharePoint Login

雨燕双飞 提交于 2020-02-04 04:02:09

问题


string urlSite = "https://intranet.site.dk";
string user = "myuser@vid.net.local";
string pwd = "mypass";

using (ClientContext clientContext = new ClientContext(urlSite))
{
    SecureString passWord = new SecureString();
    foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
    clientContext.Credentials = new SharePointOnlineCredentials(user, passWord);
    Web web = clientContext.Web;
    clientContext.Load(web);
    clientContext.ExecuteQuery();
    Console.WriteLine(web.Title);
    Console.ReadLine();
}

I'm trying to login on a sharepoint web site.
This code is what i could come up with.
No matter what i do, i'll get the Not authorized (401)
But if i type the exactly same in my browser, it's working fine..
Can anyone see the problem?


回答1:


make your code simple ;) use this codes:

using (ClientContext clientContext = new ClientContext(urlSite))
            {
                clientContext.Credentials = new NetworkCredential(user, pwd, domain);
                Web web = clientContext.Web;
                clientContext.Load(web);
                clientContext.ExecuteQuery();
                Console.WriteLine(web.Title);
                Console.ReadLine();
            }


来源:https://stackoverflow.com/questions/36424603/c-sharp-windows-application-sharepoint-login

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!