Create New iteam Sharepoint List

Sagarp
Posted by Sagarp under SharePoint category on | Points: 40 | Views : 2933
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"/>

Comments or Responses

Login to post response