I am new to sharepoint, I am using sharepoint online, and I am writing code to simply print the websites title and date created. here is my code:
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);
}
}
}
}
First I did not have the dll files Microsoft.Sharepoint.client.dll and Microsoft.Sharepoint.client.runtime.dll so I installed the Sharepoint Client SDK from microsoft, and I got the dll files in my C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI.
on running the code I get the exception on following line:
clientContext.Credentials = new SharePointOnlineCredentials("{myusername}", password);
Exception:
System.Runtime.Interopservices.COMException {"Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"}
Stack Trace:
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)
For clarification, I've entered correct credentials and there is nothing wrong with the code because the above same code is running perfectly on a different system which has Windows 8 32 bit OS and visual studio 2013.
It is failing on my other 2 systems which are running on Windows 7 and 8, both 64 bit. does it have anything to do with Windows? Sorry for the long post, but there were similar questions on stackoverflow on which i couldn't find my answer so i wanted to narrow down my problem.
has the same error, solved with the installation of sharepoint.client 16 version in nuget console PM>Install-Package Microsoft.Sharepoint.2013.Client.16
thanks guys!
Please install SharePoint Server 2013 Client Components SDK.
Client components also contain required COM library, see related link.
I was getting a similar error. I updated the Microsoft SharePoint client DLLs and now it works. I do not need to install the SDK any more. Downloaded the DLLs from here- https://www.nuget.org/packages/Microsoft.Sharepoint.2013.Client.16/
User contributions licensed under CC BY-SA 3.0