Inserting/Updating/Deleting the items in  share point list by C# coding:
| using(SPSite site = newSPSite("http://website url/")) | 
| 02 | // Or SPContext.Current.Site.Url | 
| 03 | { | 
| 04 |     using(SPWeb Web = site.OpenWeb()) | 
| 05 |     { | 
| 06 |             Web.AllowUnsafeUpdates = true; | 
| 07 | 
| 08 |             // Open List | 
| 09 |              SPList list = Web.Lists["MyList"]; | 
| 10 | 
| 11 |             // Add new item in List | 
| 12 |              SPListItem item = list.Items.Add(); | 
| 13 |              item["Title"] = "Test Title"; | 
| 14 |              item["Description"] = "Test Description"; | 
| 15 |              item.Update(); | 
| 16 | 
| 17 |             // Get Item ID | 
| 18 |              listItemId = item.ID; | 
| 19 | 
| 20 |             // Update the List item by ID | 
| 21 |              SPListItem item = list.GetItemById(listItemId); | 
| 22 |              item["Description"] = "Update Description"; | 
| 23 |              item.Update(); | 
| 24 | 
| 25 |             // Delete item | 
| 26 |              SPListItem item = list.GetItemById(listItemId); | 
| 27 |              item.Delete(); | 
| 28 | 
| 29 |             Web.AllowUnsafeUpdates = false; | 
| 30 |        } | 
| 31 |  } | 
 
No comments:
Post a Comment