我是sharepoint的新手,我在线使用sharepoint,而我正在编写代码来简单地打印网站标题和创建的日期。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Security;
namespace SharepointAccessList
{
class Program
{
static void Main(string[] args)
{
using (ClientContext clientContext = new ClientContext("https://{sitename}.sharepoint.com//"))
{
SecureString password = new SecureString();
foreach (char c in "{mypassword}".ToCharArray()) password.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("{myusername}", password);
Web oWebsite = clientContext.Web;
clientContext.Load(oWebsite);
clientContext.ExecuteQuery();
Console.WriteLine("Title: {0} Created: {1}", oWebsite.Title, oWebsite.Created);
}
}
}
}
首先我没有dll文件Microsoft.Sharepoint.client.dll和Microsoft.Sharepoint.client.runtime.dll所以我从microsoft安装了Sharepoint Client SDK,我在我的C:\ Program中得到了dll文件Files \ Common Files \ Microsoft Shared \ Web Server Extensions \ 15 \ ISAPI。
运行代码我在下一行得到了例外:
clientContext.Credentials = new SharePointOnlineCredentials("{myusername}", password);
例外:
System.Runtime.Interopservices.COMException {“灾难性故障(HRESULT异常:0x8000FFFF(E_UNEXPECTED))”}
堆栈追踪:
at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.EnsureInited()
at Microsoft.SharePoint.Client.Idcrl.ManagedIdcrl.LogonIdentity(String username, SecureString password)
at Microsoft.SharePoint.Client.SharePointOnlineCredentials..ctor(String username, SecureString password)
at SharepointAccessList.Program.Main(String[] args) in c:\Users\Fortune4\Documents\Visual Studio 2012\Projects\SharepointAccessList2\SharepointAccessList2\Program.cs:line 21
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
为了澄清,我输入了正确的凭据并且代码没有任何问题,因为上面相同的代码在具有Windows 8 32位操作系统和visual studio 2013的其他系统上完美运行
我在Windows 7和8上运行的其他两个系统都失败了,这两个系统都是64位。 它与Windows有什么关系吗? 很抱歉这篇文章很长,但是在stackoverflow上也有类似的问题,我找不到答案,所以我想缩小我的问题范围。
答案 0 :(得分:3)
有相同的错误,通过在nuget控制台中安装sharepoint.client 16版本解决了 PM> Install-Package Microsoft.Sharepoint.2013.Client.16
谢谢你们!
答案 1 :(得分:0)
请安装SharePoint Server 2013 Client Components SDK。
客户端组件还包含必需的COM库,请参阅相关的link。
答案 2 :(得分:0)
我遇到了类似的错误。我更新了Microsoft SharePoint客户端DLL,现在它可以工作了。我不再需要安装SDK了。 从这里下载了DLL- https://www.nuget.org/packages/Microsoft.Sharepoint.2013.Client.16/