开发者

SharePoint Site/List Enumeration

Hello I have this code that goes through the SharePoint site and it looks at all the lists, and returns then to a label. Basically I want it to only grab the current site lists only, and not any subsites under right now I have my SP site like this:

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

It duplicates Images Documents the normal lists and MyList10 shows up. All I want is Documents Images and MyListA Thank You

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

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

            foreach (SPWeb subSite in subSites)
            {

                SPListColle开发者_如何学Cction collList = subSite.Lists;

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

                subSite.Close();
            }
        }


All you need is this:

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

Also mention, that code you provided have some memory leaks.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜