.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Creating a List programmatically with Custom List Template Types using sharepoint .

Posted By:Sagar Pardeshi       Posted Date: February 28, 2011    Points: 15    Category:    URL: http://www.dotnetspark.com  

Creating a List programmatically with Custom List Template Types using sharepoint .
 

namespace customl.Customlist
{
    [ToolboxItemAttribute(false)]
    public class Customlist : WebPart
    {
        Button btn;
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            btn = new Button();
            btn.Text = "show";
            btn.Click += new EventHandler(btn_Click);
            Controls.Add(btn);
        }

        void btn_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb web = SPContext.Current.Web;
                web.AllowUnsafeUpdates = true;

SPListTemplateCollection listTemplates = site.GetCustomListTemplates(mySite);
SPListTemplate template = listTemplates["Enter template name here"];
Guid listId = web.Lists.Add("checkcustomlist", "The new custom list", template);
SPList list = web.Lists[listId];

web.AllowUnsafeUpdates = false;
            }
            catch (Exception ex)
            {
                Context.Response.Output.Write("Error (btn_Click): " + ex.Message.ToString());
            }

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

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend