I need make CSOM call, when I new a context, I need the site url. But I only have list document url, such as

https://XXX.sharepoint.com/teams/AAA/Shared Documents/

Should I remove last "Shared Documents/" to get site url ?

I can't use server dll because my code not based on SPO server. Thanks.


3 Answers 3


What I have understood is, you only have your document library URL:

https://XXX.sharepoint.com/teams/AAA/Shared Documents/

And you want to get the context of SharePoint Site for this Document Library.

So, getting context of site required Site URL, Document Library URL will not help.

If you are sure that your URL will always be in same form, then I would prefer to split the string by "Shared Documents" and use the first part of the string as Site URL.

For splitting you may refer this

  • 2
    Not always "shared documents", always list url. I don't know whether all list url is this format http://siteurl/listname/
    – zxy_snow
    Commented Jul 14, 2017 at 10:27

If you are using SharePoint 2013 or higher, you can use ctx object on JavaScript side to reach many information about current context.

Here is chrome console with current context.

Here is ctx object on chrome console

  • My code not based on SPO, I only use CSOM to call. That is, I only have site url to make CSOM context.
    – zxy_snow
    Commented Jul 15, 2017 at 8:04

I assume that you are simply trying to create a new ClientContext object, but do not have the url for the site.

You do not need to work out what the site url is.

You can simply use the url to the document library and that will work. The following will establish a ClientContext to https://XXX.sharepoint.com/teams/AAA

ClientContext context = ClientContext("https://XXX.sharepoint.com/teams/AAA/Shared Documents/");

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.