4

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

5

No, this is not supported.

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

1
  • 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 Apr 15 '13 at 9:17
2

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.

6
  • 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
  • 1
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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