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

Top 5 Contributors of the Month

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

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

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

Creating a List programmatically with Custom List Template Types

namespace customl.Customlist
    public class Customlist : WebPart
        Button btn;
        protected override void CreateChildControls()
            btn = new Button();
            btn.Text = "show";
            btn.Click += new EventHandler(btn_Click);

        void btn_Click(object sender, EventArgs e)
                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("Test Custom List", "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)


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

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