Get a website URL based on a GUID? (SharePoint)

is there any code example that shows me how to get the url for the site if I know guid?

I currently have this code to get all sites within a site collection.

private void getSites() { SPSite oSiteCollection = SPContext.Current.Site; SPWebCollection collWebsite = oSiteCollection.AllWebs; for (int i = 0; i < collWebsite.Count; i++) { ddlParentSite.Items.Add(new ListItem(collWebsite[i].Title, collWebsite[i].ID.ToString())); } } 

Thanks in advance.

+4
source share
1 answer

SPSite has a GUID constructor

 using(SPSite site = new SPSite(guid)) { return site.Url; } 

And SPSite has an OpenWeb method (GUID)

 using(SPSite site = new SPSite("http://somesite")) { using (SPWeb web = site.OpenWeb(guid)) { return web.Url; } } 
+8
source

Source: https://habr.com/ru/post/1335776/


All Articles