programatically create custom list in sharepoint ?

01namespace customl.Customlist
02{
03    [ToolboxItemAttribute(false)]
04    public class Customlist : WebPart
05    {
06        Button btn;
07        protected override void CreateChildControls()
08        {
09            base.CreateChildControls();
10            btn = new Button();
11            btn.Text = "show";
12            btn.Click += new EventHandler(btn_Click);
13            Controls.Add(btn);
14        }
15 
16        void btn_Click(object sender, EventArgs e)
17        {
18            try
19            {
20                SPWeb web = SPContext.Current.Web;
21                web.AllowUnsafeUpdates = true;
22                web.Lists.Add("checkCustomlist", "The new custom list", SPListTemplateType.GenericList);
23                web.AllowUnsafeUpdates = false;
24            }
25            catch (Exception ex)
26            {
27                Context.Response.Output.Write("Error (btn_Click): " + ex.Message.ToString());
28            }
29 
30        }
31        protected override void Render(HtmlTextWriter writer)
32        {
33            base.Render(writer);
34        }
35    }
36}

Comments