1

I have a sharepoint web application, with two subsites "test1" and "test2".

enter image description here I am trying to get the subsites using classes from Microsoft.SharePoint.Client namespace.

var context = new ClientContext(string.Format("http://{0}", "www05:48042"));

context.Credentials = new NetworkCredential(credentials.Login, credentials.Password);
var sites = context.Web.Webs;
context.Load(sites);

context.ExecuteQuery();

Login and password are correct. However, I am always getting an empty collection in webs, but should get at least 2 elements. What am I doing wrong? Any suggestions?

3
  • 2
    But those are not subsites, instead those are two different site collections Commented Feb 7, 2018 at 11:34
  • 1
    and AFAIK, client context does not expose objects like SPWebApplication Commented Feb 7, 2018 at 11:39
  • I tried it, it is also empty. Commented Feb 7, 2018 at 11:43

1 Answer 1

1

Those are not subsites instead they are different site collections

Pages are what you actually see and use on SharePoint. A Site is a collection of pages. A SiteCollection is, as the name indicates, a collection of sites. A WebApplication is a collection of SiteCollections.

and AFAIK, client context does not expose objects like SPWebApplication, you can try PowerShell though:

Get-SPSite -limit all -WebApplication http://yourWebapplicationUrl | Ft -autosize -wrap | Out-File -FilePath "PathToYourFile"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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