using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace SPSEDUproject.EDUWebPartListName
{
    [ToolboxItemAttribute(false)]
    public class EDUWebPartListName : WebPart
    {
        string strListsName = String.Empty;

        protected override void CreateChildControls()
        {
            DisplayListsName();
        }

        private void DisplayListsName()
        {
            using (SPSite site = new SPSite("http://spsedu"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    SPListCollection listsName = web.Lists;

                    foreach (SPList List in listsName)
                    {
                        strListsName += List.Title;
                        strListsName += "<br />";
                    }
                }
            }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            writer.Write(strListsName);
        }
    }
}

// 1. SPSite를 잡자 --> 주소(url)주고 SPSite를 잡는다. (using문 사용할 것!)

// 2. SPWeb 을 잡자 --> 여기서는 RootWeb으로 매핑시켰다.  (using문 사용할 것!)

// 3. SPListCollection 을 잡자 --> Web.Lists 프로퍼티로 목록들을 매핑시켰다.

// 4. Foreach 문을 사용하여 컬렉션(리스트명)을 열거한다.  ex) foreach (SPList List in listsName) { }

// 5. 리스트의 이름(Title)을 넣어라.  ex) strListsName += List.Title;



 

Posted by holland14
: