开发者

Get site URL based on GUID? (SharePoint)

开发者 https://www.devze.com 2023-02-04 08:38 出处:网络
is there any code example out there that shows me how to get the url for a site if I know the guid? Currently I have this code to ge开发者_开发知识库t all sites within the site collection.

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

Currently I have this code to ge开发者_开发知识库t all sites within the 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.


SPSite has a GUID constructor

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

And SPSite has a OpenWeb(GUID) method

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

精彩评论

暂无评论...
验证码 换一张
取 消