Social Icons

Pages

Monday, January 7, 2013

SharePoint Document Library C# - Delete all the document versions using OM


In this article, I am going show how to delete all the document versions details from SharePoint document library.


private void DeleteAllVersion()
        {
            try
            {
                    DialogResult dr = MessageBox.Show("Are you sure you want to send all provious versions associated with this file to the site Recycle Bin?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        SPSite Site = new SPSite(requestUrl);
                        using (SPWeb web = Site.OpenWeb())
                        {
                            SPList list = web.Lists[DocLibrary];
                            SPListItem item = list.GetItemById(DocumentID);
                            SPListItemVersionCollection Fileversioncollection = item.Versions;
                            Fileversioncollection.RecycleAll();
                            MessageBox.Show("Document versions have been successfully deleted.", "Message");
                        }
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message");
                return;

            }
        }
 

1 comment:

  1. Hi Mathy,
    I am newbie in Sharepoint, would like to request you to provide me working code for Deleting all files in folder using CSOM c#.

    ReplyDelete