【发布时间】:2014-01-02 13:20:51
【问题描述】:
我是 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);
}
}
}
}
首先我没有 Microsoft.Sharepoint.client.dll 和 Microsoft.Sharepoint.client.runtime.dll 的 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 位)的其他 2 个系统上失败。 它与Windows有什么关系? 很抱歉发了这么长的帖子,但是在 stackoverflow 上有类似的问题,我找不到我的答案,所以我想缩小我的问题范围。
【问题讨论】:
-
这行得通吗?:clientContext.Credentials = new NetworkCredential(myusername, password);
-
不,我在使用 SharepointOnlineCredentials 之前尝试过此方法,但服务器在运行时抛出 403 禁止错误。
标签: c# windows visual-studio-2010 sharepoint dll