SharePoint站点/列表枚举

时间:2011-02-07 16:34:10

标签: c# sharepoint-2007

您好我有这段代码通过SharePoint网站,它会查看所有列表,然后返回标签。基本上我希望它只能抓住当前的网站列表,而不是现在的任何子网站我有这样的SP网站:

Main Site
-Documents
-Images
-MyListA
--Engineering (subSite)
---Documents
---Images
---MyList10

它复制正常列表和MyList10显示的图像文档。我想要的只是文件图片和MyListA谢谢你

        string webUrl = SPContext.Current.Site.Url.ToString();

        using (SPWeb oWebsite = new SPSite(webUrl).OpenWeb())
        {
            SPWebCollection subSites = oWebsite.Webs;

            foreach (SPWeb subSite in subSites)
            {

                SPListCollection collList = subSite.Lists;

                foreach (SPList oList in collList)
                {
                    Label1.Text = SPEncode.HtmlEncode(oList.Title);
                }

                subSite.Close();
            }
        }

1 个答案:

答案 0 :(得分:2)

所有你需要的是:

    foreach (SPList list in SPContext.Current.Web.Lists)
    {
       Label1.Text = SPEncode.HtmlEncode(list.Title); // notice that it will overwrite label text every time
    }

另请注意,您提供的代码存在一些内存泄漏。