public void Delete(SPList list, SPListItem item) { cacheService.RemoveByTags(new[] { GetTag(list.Id) }, CacheScope.Context | CacheScope.Process); using (var clientContext = new SPContext(list.SPWebUrl, credentials.Get(list.SPWebUrl))) { SP.List spList = clientContext.ToList(list.Id); SP.ListItem spItem = clientContext.ToList(list.Id).GetItemById(item.Id); spItem.DeleteObject(); clientContext.ExecuteQuery(); } }
/// <summary> /// Deletes the selected item in the list view, then reloads the data. /// </summary> private void DeleteButton_Click(object sender, EventArgs e) { if (RecipesListView.SelectedItems.Count != 0) { var selectedRecipe = RecipesListView.SelectedItems[0]; Guid uniqueId = Guid.Parse(selectedRecipe.Tag.ToString()); SP.ListItem listItem = RecipesList.GetItemByUniqueId(uniqueId); listItem.DeleteObject(); Context.ExecuteQuery(); LoadRecipes(); } }
protected void DeleteListItem() { try { List testeList = context.Web.Lists.GetByTitle("Teste"); Microsoft.SharePoint.Client.ListItem item = testeList.GetItemById(6); item.DeleteObject(); context.ExecuteQuery(); } catch (Exception ex) { lbl1.Text = ex.Message; throw; } }
private void Delete(Project emp) { if (oList != null) { // Delete if (emp.Id != 0) { // Assume that there is a list item with ID=2. ListItem listItem = oList.GetItemById(emp.Id); if (listItem != null) { listItem.DeleteObject(); context.ExecuteQuery(); RemoveItemOnView(emp.Id); } } } }
private void deleteButton_Click(object sender, RoutedEventArgs e) { string UserName = "******", Password = "******"; ClientContext ctx = new ClientContext("https://omisayeduiu.sharepoint.com/sites/sayeddev"); SecureString passWord = new SecureString(); foreach (char c in Password.ToCharArray()) { passWord.AppendChar(c); } ctx.Credentials = new SharePointOnlineCredentials(UserName, passWord); Web myWeb = ctx.Web; Microsoft.SharePoint.Client.List sectionsList = myWeb.Lists.GetByTitle("sectionInfo"); Microsoft.SharePoint.Client.ListItem item = sectionsList.GetItemById(Convert.ToInt32(deleteId.Text.Trim())); item.DeleteObject(); ctx.ExecuteQuery(); this.show(); }
public void DeleteItem(string ListName, int Id) { try { SP.Web web = context.Web; SP.List list = web.Lists.GetByTitle(ListName); SP.ListItem item = list.GetItemById(Id); if (item != null) { item.DeleteObject(); context.ExecuteQuery(); } else { throw new Exception("Item does not exist"); } } catch (Exception ex) { throw new Exception("Error updating SharePoint list data: " + ex.Message); } }