Domanda

I want to insert new item in SharePoint list using web part . It is possible with using c# or web services.

È stato utile?

Soluzione

You can add new item to SharePoint List using one of this

  • Server Side Object model via C#
  • REST Endpoint.
  • Client Side Object Model.
  • Web Services and JQuery.
  • JSOM

Via Server Side Object model via C#

  • Create a sharePoint Solution via Visual Studio.
  • Add New Item > Add Visual Web Part.
  • Add Labels and Textbox that you need to added it to your list.

Add the following code

void Addnewitem()
{

SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists[TextBox1.Text].Items;

SPListItem item = listItems.Add();

item["Title"] = TextBox2.Text;
item["Stock"] = Convert.ToInt32(TextBox3.Text);
item["Return Date"] = Convert.ToDateTime(TextBox4.Text);
item["Employee"] = TextBox5.Text;

item.Update();
}

For more details check How to: Add or Delete List Items

Via REST.

If you need to use Rest interface check Working with lists and list items with REST

Via Client Side Object Model

If you need to use Client Side Object Model (.Net Managed) , you should check How to: Create, Update, and Delete List Items via CSOM

Via Web Services

If you need to use Web Services and JQuery , Check also CRUD On List Items Using Web Services And jQuery In SharePoint 2013

Via JSOM

If you need to use JSOM check CRUD Operation On List Items Using JSOM In SharePoint 2013

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top