What's the relationship between list url and site url

%3CLINGO-SUB%20id%3D%22lingo-sub-87363%22%20slang%3D%22en-US%22%3EWhat's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87363%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20make%20CSOM%20call%2C%20when%20I%20new%20a%20context%2C%20I%20need%20the%20site%20url.%20But%20I%20only%20have%20list%20document%20url%2C%20such%20as%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2FXXX.sharepoint.com%2Fteams%2FAAA%2FShared%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FXXX.sharepoint.com%2Fteams%2FAAA%2FShared%3C%2FA%3E%20Documents%2F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EShould%20I%20remove%20last%20%22Shared%20Documents%2F%22%20to%20get%20site%20url%20%3F%20Thanks.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87814%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87814%22%20slang%3D%22en-US%22%3EHow%20can%20I%20use%20CSOM%20when%20I%20don't%20know%20site%20url%20%3F%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87813%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87813%22%20slang%3D%22en-US%22%3E%3CP%3ECan%20you%20give%20some%20more%20details%20on%20what%20you%20are%20trying%20to%20do.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20are%20for%20example%20using%20CSOM%20you%20could%20get%20a%20list%20object%20using%20the%20list%20url%20and%20then%20via%20list.ParentWeb%20get%20the%20url%20of%20the%20site%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87770%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87770%22%20slang%3D%22en-US%22%3E%3CP%3ESharePoint%20list%2Flibrary%26nbsp%3Burl%20is%20basically%20adding%20the%20library%20name%20to%20the%20site%20url%20and%20in%20your%20case%26nbsp%3B%26nbsp%3Bit%20is%20like%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESite%20URL%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fxxx.sharepoint.com%2Fteams%2FAAA%2FShared%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FXXX.sharepoint.com%2Fteams%2FAAA%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EDocument%20Library%20URL%20is%20%3CA%20href%3D%22https%3A%2F%2Fxxx.sharepoint.com%2Fteams%2FAAA%2FShared%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FXXX.sharepoint.com%2Fteams%2FAAA%2F%3C%2FA%3E%20%2B%20Shared%20Documents%20i.e.%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fxxx.sharepoint.com%2Fteams%2FAAA%2FShared%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FXXX.sharepoint.com%2Fteams%2FAAA%2FShared%3C%2FA%3E%20Documents%2F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20to%20get%20the%20site%20url%20just%20remove%20the%20Shared%20documents%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87762%22%20slang%3D%22en-US%22%3ERe%3A%20RE%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87762%22%20slang%3D%22en-US%22%3EI%20don't%20have%20_spPageContextInfo.%20My%20code%20not%20based%20on%20SPO.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87681%22%20slang%3D%22en-US%22%3ERE%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87681%22%20slang%3D%22en-US%22%3EYou%20can%20get%20site%20url%20by%20%22_spPageContextInfo.webAbsoluteUrl%22%20also.%20I%20think%20it%20would%20be%20easy%20for%20you.%20No%20need%20to%20make%20a%20CSOM%20call%20for%20that.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87587%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87587%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3ERefer%20the%20below%20Link%20for%20sharepoint%20URL%20structure%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fwww.nothingbutsharepoint.com%2F2010%2F03%2F25%2Fsharepoint-url-basics-aspx%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.nothingbutsharepoint.com%2F2010%2F03%2F25%2Fsharepoint-url-basics-aspx%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20know%20Document%20libarry%20name%20then%20remove%20only%20the%20document%20libary%20name%2C%20you%20will%20get%20the%20site%20url%2C%20Or%20if%20yave%20have%20list%20name%20%2C%20you%20need%20to%20remove%20from%20%2FLists%2Flistname%20then%20you%20will%20get%20the%26nbsp%3B%3CSPAN%3Esite%20url%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87586%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87586%22%20slang%3D%22en-US%22%3EThe%20truth%20is%2C%20I%20don't%20know%20the%20the%20sitename.%20I%20only%20have%20the%20string%20of%20list.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87372%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87372%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EIn%20basically%20site%20url%20forming%20like%20https%2F%2Fxxx.com%2Fsites%2Fsitename%20and%20your%20case%26nbsp%3B%3CSPAN%3Ehttps%2F%2Fxxx.com%2Fteams%2Fsitename%26nbsp%3Bso%20if%20you%20remove%20after%20site%20name%20you%20will%20get%20site%20url%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87370%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87370%22%20slang%3D%22en-US%22%3EDo%20you%20have%20some%20document%20of%20this%20%3F%20I%20see%20some%20other%20list%20url%20like%20this%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fxxx.com%2Fteams%2Faa%2Fbb%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fxxx.com%2Fteams%2Faa%2Fbb%2F%3C%2FA%3E%3CBR%20%2F%3EBB%20not%20always%20shared%20documents%2C%20should%20I%20remove%20last%20segment%20to%20get%20site%20url%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-87365%22%20slang%3D%22en-US%22%3ERe%3A%20What's%20the%20relationship%20between%20list%20url%20and%20site%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-87365%22%20slang%3D%22en-US%22%3E%3CP%3EYes%20%2C%20you%20are%20correct%2C%20after%20removing%20%2Fshared%20dodument%2F%20%26nbsp%3Byou%20will%20get%20the%20site%20url.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
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
Highlighted

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

Highlighted
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?
Highlighted

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

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

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

 

Highlighted
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.
Highlighted
I don't have _spPageContextInfo. My code not based on SPO.
Highlighted

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

Highlighted

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

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