What's the relationship between list url and site url

Microsoft

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 ? Thanks.

10 Replies

Yes , you are correct, after removing /shared dodument/  you will get the site url.

Do you have some document of this ? I see some other list url like this
https://xxx.com/teams/aa/bb/
BB not always shared documents, should I remove last segment to get site url?

Hi,

In basically site url forming like https//xxx.com/sites/sitename and your case https//xxx.com/teams/sitename so if you remove after site name you will get site url

The truth is, I don't know the the sitename. I only have the string of list.

Hi,

Refer the below Link for sharepoint URL structure 

http://www.nothingbutsharepoint.com/2010/03/25/sharepoint-url-basics-aspx/

 

If you know Document libarry name then remove only the document libary name, you will get the site url, Or if yave have list name , you need to remove from /Lists/listname then you will get the site url

 

You can get site url by "_spPageContextInfo.webAbsoluteUrl" also. I think it would be easy for you. No need to make a CSOM call for that.
I don't have _spPageContextInfo. My code not based on SPO.

SharePoint list/library url is basically adding the library name to the site url and in your case  it is like

 

Site URL https://XXX.sharepoint.com/teams/AAA/

 

Document Library URL is https://XXX.sharepoint.com/teams/AAA/ + Shared Documents i.e. https://XXX.sharepoint.com/teams/AAA/Shared Documents/

 

 

So to get the site url just remove the Shared documents

Can you give some more details on what you are trying to do. 

 

If you are for example using CSOM you could get a list object using the list url and then via list.ParentWeb get the url of the site

How can I use CSOM when I don't know site url ?