【问题标题】:TFS SharePoint retrieving list of projectsTFS SharePoint 检索项目列表
【发布时间】:2020-12-04 22:02:03
【问题描述】:

背景 在 TFS 中,每当您创建新项目时,都会在 http://sharepoint/sites/projectname 下创建一个新的 SharePoint 网站。要查看这些子网站,以下是描述它的链接:

http://blog.aggregatedintelligence.com/2009/04/viewing-list-of-tfs-portals-in.html

现在我想创建一个 SharePoint Webpart 来检索http://sharepoint/sites 下的所有项目。我使用以下方法:

        using (SPSite site = new SPSite("http://sharepoint/sites/"))
        {

            foreach (SPWeb web in site.AllWebs)
            {
                //do operations here
            }
        }

现在的问题是它不起作用。该站点不会检索这些目录下的站点。我该怎么做?

【问题讨论】:

    标签: sharepoint tfs


    【解决方案1】:

    我希望您没有得到任何回报的原因是因为 /sites/ 并不是 SharePoint 上的真正网站集,如果您尝试访问 /sites/ 作为SharePoint 服务器。

    您可能只需要从根网站返回所有网站,然后只过滤路径名,无论它是否包含/sites/。我相信这就是管理中心在 Web 应用程序列表中显示网站列表的方式。

    【讨论】:

    • 是的,我这样做了,但问题是它需要“帐户作为系统操作”权限。有没有办法让我们不需要向访问该站点的所有用户授予该访问权限? foreach(SPSite s in wa.Sites) { using(SPSite site = s) { foreach (SPWeb web in site.RootWeb.GetSubwebsForCurrentUser()) { if (web.Url.Contains("/Sites/")) { //在这里做事 } } } }
    • 重新输入上面的代码:SPWebApplication wa = SPWebApplication.Lookup(new Uri("sharepoint")); foreach(SPSite s in wa.Sites) { using(SPSite site = s) { foreach (SPWeb web in site.RootWeb.GetSubwebsForCurrentUser()) { if (web.Url.Contains("/Sites/")) { //在这里做事 } } } Controls.Add(table); }
    • 啊找到了答案:RunWithElevatedPrivileges
    猜你喜欢
    • 2019-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-06
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多