CRM 2011 – Could not load file or assembly ‘Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its dependencies. The system cannot find the file specified.

continueing with my current project of trying to automatically create Sharepoint folders and copy files into sharepoint.

I have now done this with a webservice and a web application.  I was getting this error when I published the web application to the live server, the code was working on my local dev environment.

This time I was coding the web application and when it got to the point of trying to connect to sharepoint it was throwing this error

Could not load file or assembly ‘Microsoft.SharePoint.Client, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its dependencies. The system cannot find the file specified.

The key to this error (in my opinion) was the fact it could not find the file.  This basically seemed to say it could not find Microsoft.SharePoint.Client.dll

This seemed a bit odd because I had added the dll as a reference but looking in the bin directory of the deployed web application.

This other time I have had an error similar to this is when I have tried to run the CRM plugin registration tool and the folder hasn’t got the microsoft.crm.sdk.dll and maybe a couple of other dl’s.

So once I copied the sharepoint dll’s into the bin directory of my web application it was working

CRM 2011 – Transactions and Sharepoint Online

I have previously blogged about using authentication with sharepoint online and I am at it again.

https://crmbusiness.wordpress.com/2012/06/20/crm-2011-authenticating-with-sharepoint-online-2010-from-a-net/

To summarise the blog above you basically have to login to Sharepoint online before you can create the folders and this involves logging on to Office365.  The code checks to see if there any cookies which would have been created if you had logged on and if there aren’t any it logs on and creates those cookies (if I remember correctly).

This caused me some problems when trying to use this code within a CRM plugin.  Firstly I was getting problems because some of my code was a USING statement, I have a couple of good blogs, web pages below.

http://stackoverflow.com/questions/248961/c-sharp-using-statement-catch-error

http://msdn.microsoft.com/en-us/library/aa355056.aspx

The main reason this doesn’t work in a plugin is because I think it creates another transaction and this breaks the plugin transaction.

I’m not totally sure about this transaction below but it’s what I think is happening.

I think CRM plugins are based around WCF which is a transactional and my understanding of this is you can’t have a transaction within a transaction.

I had written some code which creates some sharepoint folders based on the document locations records, basically when a project record was being created I wanted to create the sharepoint folder and some other folders within that folder.

I tested the code working from my machine and manually created a an IOrganizationService and getting/retrieving and creating CRM entities etc.  This code also worked and created the sharepoint folders.

BUT…

when I then put this into a plugin I was getting transaction errors, this was difficult to debug but when I tried to connect to Sharepoint online it crashed out with a transaction error.

To get round this I decided to put the code into a webservice and call that from my plugin and this finally worked.

I could be wrong about transactions and there could be a better way to do this but I’m just happy I got the thing working

CRM 2011 – Understanding document locations

I have been working with CRM 2011 and Sharepoint online.  Out of the box CRM 2011 has some great integration with Sharepoint and it can create and view folders semi automatically.

The current project wanted this to be automatic.

The first thing I had to do was understand how this worked and it’s a little bit unusual.  Sharepoint integration works in a similar fashion to email in CRM basically CRM doesn’t not do any sharepoint integration in a similar way to CRM does not do any emailing.

Emailing in CRM is passed off to either the Outlook add on or a CRM router.

My understand of Sharepoint and CRM is similar.

CRM creates entities called Document Locations and these hold relative sharepoint url information.  When you click on Documents in the left hand navigation options it creates a series of relative document locations, working back from the Sharepoint site entity.

e.g. for a new account called Test

Sharepoint site = default

document location – account

document location – Test

The two document locations will have a parent site or location link in them.

The way to understand this is to basically think of a file a structure on your C drive and imagine the default collection is not a sharepoint site but C:\

C:\account\Test

so to automate this for a new account I would need to add two new document locations account and Test.

I was doing this for a custom entity called project and the user could add lots of projects

c:\project\proj1

c:\project\proj2

c:\project\proj3

so when I was create a document location for project I had to check to see if a project had been created before, if it had then I knew the project document location was already created and I could then use that and reference it in the Parent Site or Location field.

Now I get onto the fact the point Sharepoint isn’t really related in CRM because even though I can create the document location records this does absolutely nothing in Sharepoint.  All it does it create a link to where it should be in Sharepoint but doesn’t create the actual folders.

There is also nothing in the CRM SDK to create Sharepoint folders from my understanding you now have to write code using the SharePoint dll’s or SharePoint webservice.

This is quite frustrating because CRM does create the sharepoint folder if you click on documents.

 

CRM 2011 – authenticating with Sharepoint Online 2010 from a .NET

I was having a struggle to authenticate with Sharepoint Online

I was using the Client Object Model and when I was trying to create a connection to sharepoint so I could check if folders had been added for CRM but I was getting a 403 forbidden message.

In the back of mind I was thinking the problem had to be linked to SharePoint/Office 365 online which both need you to login.

This page has a good overall description of the problem, you basically need to authenticate before you can start using SharePoint 2010 Online

Remote Authentication in SharePoint Online Using Claims-Based Authentication

http://msdn.microsoft.com/en-us/library/hh147177.aspx

The only problem with code I got from here is it popped up a login if the authenticated cookies were not on the machine.  As my code would be running from a plugin I needed to automate that

Authentication with SharePoint Online and the Client Side Object Model

http://blogs.msdn.com/b/cjohnson/archive/2011/05/03/authentication-with-sharepoint-online-and-the-client-side-object-model.aspx

this code works

Part 2: “Headless” Authentication with SharePoint Online and the Client Side Object Model

http://blogs.msdn.com/b/cjohnson/archive/2011/05/14/part-2-headless-authentication-with-sharepoint-online-and-the-client-side-object-model.aspx

one gotcha to mention with the code above is you have to put on the forward slash at the end of the SharePoint url

e.g.

https://<companyname&gt;.sharepoint.com/

if you don’t put the forward slash on it won’t work.

I also had problems because my pc clock was over 5 minutes out, it wasn’t letting me login.

some other useful links regarding writing .Net code for SharePoint 2010

Common Programming Tasks in the Managed Client Object Model

http://msdn.microsoft.com/en-us/library/ee537013.aspx