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


Top 5 Contributors of the Month
david stephan

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
{
    [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("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)
        {
            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
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