.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

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)
{
	try
	{
		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();
		
		item.Update();
		mySite.AllowUnsafeUpdates = false;
		
		
		Page.Response.Write("Success");
        }
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:

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