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

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

 Subscribe to Code Snippets

Create New item in sharepoint List

Posted By:Sagar Pardeshi       Posted Date: September 05, 2013    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

Create new item in sharepoint list using server object model

protected void Create_Click(object sender, EventArgs e)
		SPWeb mySite = SPContext.Current.Web;
		SPListItemCollection listItems = mySite.Lists["Test Custom List"].Items;
		mySite.AllowUnsafeUpdates = true;
		SPListItem item = listItems.Add();
		item["Title"] = TextBox2.Text.ToString();
		mySite.AllowUnsafeUpdates = false;
catch (Exception ex)
		Page.Response.Write("failed" + ex.Message.ToString());



New Title Name:
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
       	<asp:button id="Button2" runat="server" onclick="Create_Click" text="Create"/> 


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