SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to call SharePoint from within a standard .NET class library. This will probably be hosted on a different server to SharePoint.

I just need to return an item from a list, and wondered if I needed to use the Client framework or if something like below would work:

using (SPSite site = new SPSite("http://sitecollection"))
  using (SPWeb web = site.RootWeb)
    SPList list = web.Lists["Image List"];

    // Get item by name field value

I'm currently just referencing the Microsoft.SharePoint.dll

share|improve this question
up vote 5 down vote accepted

No, this is not supported.

You need to use the web services or the Client Side Object Model (CSOM)

share|improve this answer
did for CSOM model possible to read and write in the sharepoint lists like windows application ? is there any sample code ? can you put here a link – saber tabatabaee yazdi Apr 15 '13 at 9:17

You need to use the Client Framework to instantiate an SPSite on another farm.

The reason being, is that when you instantiate SPSite, the server running the code looks into it's own farm configuration to find out what content database to get the data from.

If you're on FarmA and want to instantiate a site collection that exists in FarmB, you will get a FileNotFoundException, because that site collection only exists within a web application that is in FarmB's configuration database.

share|improve this answer
So because SP is not on the same server (but on the same domain still) it's classed as a different Farm? – Andrew Aug 5 '12 at 14:01
Well it depends, you can have multiple farms (comprised of multiple servers) in a single domain. – James Love Aug 5 '12 at 14:04
I guess what I'm asking is how do I know for sure the server running the code is on a different farm, and therefore to go down the Client Framework? – Andrew Aug 5 '12 at 14:08
The simple answer to that is where are you deploying your code to in the end? That environment will be a server on a farm. – James Love Aug 5 '12 at 14:10
I think you're confusing the concept of a SharePoint farm to another type of server farm. CRM cannot belong to a SharePoint Farm, as any server in a SharePoint Farm is registered in that farm's configuration database, visible the in Central Administration web app for that farm. – James Love Aug 5 '12 at 14:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.