C#Windows应用程序的SharePoint登录 [英] C# Windows Application SharePoint Login

查看:500
本文介绍了C#Windows应用程序的SharePoint登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
}



我试图登录的SharePoint网站。结果
该代码是我能想出什么样的。结果
不管我做什么,我会得到未授权(401)结果
但是,如果我键入完全相同在我的浏览器,它的正常工作..结果
谁能看这个问题?

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?

推荐答案

让你的代码简单;)使用此代码:

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();
            }

这篇关于C#Windows应用程序的SharePoint登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆