SharePoint and CSOM – Get an application running on SP2007 to access content and managed metadata on SP2013 using CSOM

Please don’t ask why, only know that it had to be done. The requirement was to copy documents in a library in SP2013 to another library in SP2007. This is made easier by using CSOM, but getting the right libraries can be a little tricky. I also needed to access managed metadata values, which SP2007 is like “meta-whata-now?” about.

I found that I needed to use the Microsoft.SharePoint.Client libraries from SP2010, as I was developing on the SP2007 dev box. This is because the 2013 DLLs require .NET 4.0, and 2007 uses 3.5.

So I had to:

  1. Create a new folder on your 2007 server/dev environment in C:\Program Files\Common Files\microsoft shared\Web Server Extensions\. You should already see a folder in there called “12”. Create a new one called “14”.
  2. In “14”, create another folder called “ISAPI”. This mirrors the folder structure of 2010. It’s not strictly necessary but it keeps things organised and clear.
  3. On your 2010 server (you have one, right? If not, you’ll need to find these from somewhere,) copy the client DLLs you’ll need. To do my task, I needed the following:
    1. Microsoft.SharePoint.Client
    2. Microsoft.SharePoint.Client.Runtime
    3. Microsoft.Office.Server
    4. Microsoft.SharePoint.Taxonomy
  4. If you find you need to use other libraries from 2010, add them to this same folder.
  5. In Visual Studio, add references in your project to the DLLs  in the new “14” folder.
  6. For the core Microsoft.SharePoint DLL, reference the DLL in the “12” folder.
  7. Keep to the DLLs in the 12 folder wherever possible.

That was the start of my fun crossing-the-streams adventure. I used the above to create a console app that scans given libraries by name, for tagged documents to “publish”, copying some of their managed metadata. I used a couple of good resources, which I’ll link to in the next post regarding this subject.

Advertisements

SharePoint and CSOM – Useful links

It’s been a busy couple of weeks, with my head down working on some SharePoint madness which will form at least a couple of articles to come. It involved getting SP2007 to talk to SP2013, by way of the SP2010 client dlls. It’s been as fun as it sounds

I’ve had to some serious Googling, which has generally been my friend . SO here is another list of links that I’ve found invaluable and will be returning to again and again.

Complete basic operations using SharePoint 2013 client library code
https://msdn.microsoft.com/en-us/library/office/fp179912.aspx

SharePoint 2010 – Using the Client Object Model (good CAML resources)
https://msdn.microsoft.com/en-gb/library/ff798388.aspx
https://msdn.microsoft.com/en-us/library/ee857094.aspx

SharePoint 2010 – How to retrieve list items using the COM
https://msdn.microsoft.com/en-us/library/office/ee534956(v=office.14).aspx

CAML queries and the Client Object Model (this is a really excellent resource!)
https://karinebosch.wordpress.com/2012/02/03/caml-and-the-client-object-model/

ASP:Hyperlink with dynamic url value from C# – “Object reference not set to an instance of an object”

Another gotcha found today.

I’ve created my ASP:Hyperlink field in the aspx page, with runat=”server” (oh yes, that one ain’t catching me out anymore).

In the C# code behind file, I set the URL to be one thing or another, depending on some other logic. It’s MyHyperlink.NavigateUrl = “blah.aspx”.

I run the thing, and I get “Object reference not set to an instance of an object”. Dammit!

Have I forgotten how to instantiate the field properly? It’s not in a grid view, or anything fancy like that.

A random Google result gave me the answer, phew! .NET3.5 and above requires the Hyperlink to have its NavigateUrl property set to something when created. So on the page I set it to “#”  on creation and then set it dynamically as necessary.

Another one not to forget!