Programming against Sharepoint (Online) Client Side Object Model CSOM

References

Add References to:

  1. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll
  2. C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll

Problem 1

The referenced assembly “Microsoft.SharePoint.Client, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL” could not be resolved because it has a dependency on “System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” which is not in the currently targeted framework “.NETFramework,Version=v4.0,Profile=Client”. Please remove references to assemblies not in the targeted framework or consider retargeting your project. SharepointWinFormsCSharp

Solution 1

Ensure that the project targets .Net Framework 4 and not Client Profile

Project > Properties > Application > Target Framework

Problem 2

The type or namespace name ‘SharepointOnlineCredentials’ does not exist in the namespace ‘Microsoft.SharePoint.Client’ (are you missing an assembly reference?)

Solution 2A – use this

First check that the spelling is precise including casing

Second, odd, but I copied the references to the bin folder and re-directed the reference to there and it started working. Odd thing was when I then pointed the reference back it continued to work.

Solution 2B – just creates a new problem

  1. Select Reference Microsoft.Sharepoint.Client
  2. Right-Click > Properties
  3. Embed Interop Types change from False to True
  4. Build

This returns new problem

  1. Cannot embed interop types from assembly ‘c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.Sharepoint.Client.dll” because it is missing either the ‘ImportedFromTypeLibAttribute’ attribute or the ‘PrimaryInteropAssemblyAsstribute’ attribute
  2. Cannot embed interop types from assembly ‘c:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.Sharepoint.Client.dll” because it is missing the ‘GuidAttribute’ attribute

How to use CSOM

After the above each of the use cases in the following demonstrations then worked.

How to: Complete basic operations using SharePoint 2013 client library code

            using (var context = new ClientContext("https://xxx.sharepoint.com"))
            {
                var web = context.Web;
                var login = "xx@xx";
                var password = "xxxx";
                var securePassword = new System.Security.SecureString();
                foreach (char c in password)
                {
                    securePassword.AppendChar(c);
                }
                context.Credentials = new SharePointOnlineCredentials(login, securePassword);
                context.Load(web);
                context.ExecuteQuery();
                ResusltsListBox.Items.Add(web.Title);
            }

The end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: