【发布时间】:2016-06-19 01:00:45
【问题描述】:
如何使用 C# 将文档添加到 SharePoint Online 中团队网站上的“文档”Web 部件?
我打算从 Intranet 运行我的代码。下面的代码看起来很有希望,但会引发 Microsoft.SharePoint.Client.IdcrlException。显然我的身份验证不正确,但我哪里出错了?
using (ClientContext clientContext = new ClientContext("https://MyOrg.sharepoint.com/sites/MyTeamSite/"))
{
SecureString passWord = new SecureString();
foreach (char c in "password".ToCharArray())
passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("myEmail@MyOrg.com", passWord);
Web web = clientContext.Web;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(@"c:\temp\test.txt");
newFile.Url = "test.txt";
List docs = web.Lists.GetByTitle("Documents");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
clientContext.ExecuteQuery();
}
【问题讨论】:
-
这对我有用。我还必须从这里安装 Sharepoint 客户端组件:microsoft.com/en-us/download/confirmation.aspx?id=35585 并添加对 Microsoft.Sharepoint.Client 和 Microsoft.Sharepoint.Client.Runtime 的引用
-
看来客户端组件的版本很重要,有用户描述的和你一样的错误信息,通过升级客户端组件解决了:social.technet.microsoft.com/Forums/windows/en-US/…
标签: c# sharepoint-online