Using Visual Studio, how can I reference a SharePoint 2010 site collection outside of the development machine?
-
06-10-2020 - |
سؤال
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?
المحلول
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.