[英]Connecting with sharepoint site using CSOM
我的代碼如下
try
{
string strUserName="abc";
string strPassword="123";
ClientContext context = new ClientContext(siteurl);
var credentials = new NetworkCredential(strUserName, strPassword,"Ext");
context.Credentials = credentials;
// The SharePoint web at the URL.
Web web = context.Web;
// We want to retrieve the web's properties.
context.Load(web);
// Execute the query to the server.
context.ExecuteQuery();
// Now, the web's properties are available and we could display
// web properties, such as title.
System.Console.WriteLine("Web Title");
System.Console.WriteLine(web.Title);
}
catch (Exception ex)
{
}
它給出錯誤“無法連接遠程服務器”
首先,請確保正確傳遞以下實體:
如果您嘗試連接到SharePoint Online 2013,則必須將“ NetworkCredential”替換為“ SharePointOnlineCredentials ”。 這是它的代碼片段:
string strUserName="abc";
string strPassword="123";
SecureString ssPwd = new SecureString();
strPassword.ToList().ForEach(ssPwd.AppendChar);
ClientContext context = new ClientContext(siteurl);
SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(strUserName, ssPwd);
context.Credentials = credentials;
// The SharePoint web at the URL.
Web web = context.Web;
// We want to retrieve the web's properties.
context.Load(web);
// Execute the query to the server.
context.ExecuteQuery();
接受自簽名證書:
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.