![](/img/trans.png)
[英]login to a SharePoint Site using HTML Link thorugh passing the credential
[英]SharePoint Login Credential
目前,我嘗試通過使用從列表檢索數據的SharePoint開發應用程序
現在我嘗試為登錄功能開發,錯誤顯示如下
基礎連接已關閉:發送時發生意外錯誤。
這是我的源代碼
string WebUrl = "https://xxx.sharepoint.com/sites/devspace";
string username = txtUsername.Text;
string pwd = txtPassword.Text;
ClientContext context = new ClientContext(WebUrl);
Web web = context.Web;
SecureString passWord = new SecureString();
foreach (char c in pwd.ToCharArray())
passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials(username, passWord);
try
{
context.Load(web);
context.ExecuteQuery();
lblStatus.Text = "Olla " + web.Title;
}catch(Exception ex)
{
lblStatus.Text = ex.Message.ToString();
}
有什么建議嗎? 在先進的感謝。
更新:
我正在使用SharePoint 2016,通過Windows Server AD登錄。
如前所述,您正在使用SharePoint 2016,然后請下載並安裝帶有SharePoint 2016版本Nuget包而不是SharePoint Online的CSOM:
並使用以下代碼片段:
ClientContext clientContext = new ClientContext("https://example.com/sites/testsite/");
clientContext.Credentials = new NetworkCredential("user", "password", "domain");
// Get the SharePoint web
Web web = clientContext.Web;
// Get the SharePoint list collection for the web
ListCollection listColl = web.Lists;
// Retrieve the list collection properties
clientContext.Load(listColl);
// Execute the query to the server.
clientContext.ExecuteQuery();
// Loop through all the list
foreach (List list in listColl)
{
// Display the list title and ID
Console.WriteLine("List Name: " + list.Title + "; ID: " + list.Id);
}
Console.ReadLine();
SharePoint 2016 Premise不需要使用SharePointOnlineCredentials類,只需將用戶名,密碼,域作為上面的代碼段傳遞即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.