Using Visual Studio, how can I reference a SharePoint 2010 site collection outside of the development machine?

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/164339

  •  06-10-2020
  •  | 
  •  

Question

I am creating a custom web service which needs to reference a specific site collection on our SharePoint 2010 farm.

The web service is on a development machine not part of the farm (although SharePoint 2010 is installed on it), so using the following doesn't work:

SPSite site = new SPSite(url);

"url" in this case is the url to the existing SharePoint 2010 farm, hosted externally to this development machine.

Is there a method to 'talk' to the existing SharePoint 2010 farm outside of the development environment i am using?

Était-ce utile?

La solution

When you are outside of SharePoint farm, the Client Object Model is the only way to talk with SharePoint.

https://msdn.microsoft.com/en-us/library/office/ee535451(v=office.14).aspx

SPSite site = new SPSite(url);

Instead of above, you can use

string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);

Almost every Server Object Model has an equivalent Client Object Model


Few more things

Assemblies of Client Object Model can be found in NuGet. In the package manager console paste following

Install-Package Microsoft.SharePoint.Client

Do not forget to specify authentication credentials.

clientContext.Credentials = new NetworkCredential("user", "password", "domain");

Do a google, you will find so many ways to accomplish your goal.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top