Get site URL based on GUID? (SharePoint)

て烟熏妆下的殇ゞ 提交于 2019-12-23 13:23:17

问题


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 get 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.


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/4709212/get-site-url-based-on-guid-sharepoint

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!