Let's have, for example, this url: http://corp.com/sites/project1/documents/forms/allitems.aspx
.
Is there an efficient way to analyse this full url to extract site and web url?
- The web application url is
http://corp.com
(this one is easy to find, as it's the scheme + host) - The site url is
http://corp.com/sites/project1
- The web url is
http://corp.com/sites/project1
When a SPContext
is available, this is easy, but what about an external application? Typically, what about from a PowerShell script?
$fullUrl = "http://corp.com/sites/project1/documents/forms/allitems.aspx"
$siteUrl = ___($fullUrl)
$site = Get-SPSite $siteUrl
I know I could play with Get-SPSite -Limit All
and compare url, but it may be tricky when nesting site collection, or have a large number of site collection.
Actually, I'm hoping Microsoft have an utility class that will do the job (but I didn't find it yet).
Any advise?