Let’s see how we can delete document from SharePoint document library.
Here is the sample code;
private void DeleteDocument(){try{DialogResult dr = MessageBox.Show(" Are you sure want to send the item to the site Recycle Bin?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);if (dr == DialogResult.Yes){this.Cursor = Cursors.WaitCursor;int DocID = DocumentID;string DocLib = DocLibrary Name;SPSite Site = new SPSite(URL);using (SPWeb web = Site.OpenWeb()){SPList Selectedlist = web.Lists[DocLib];SPListItem item = Selectedlist.GetItemById(DocID);item.Recycle();MessageBox.Show("Document has successfully Recycled", "Message");this.Cursor = Cursors.Default;}}}catch (Exception ex){this.Cursor = Cursors.Default;MessageBox.Show(ex.Message, "Message");return;}}
No comments:
Post a Comment