The following code deletes all the files in the Document Library. I’ve also added a counter so you can keep an eye on the progress. Create a console application, add the SharePoint.DLL (containing the SharePoint API) and you are good to go. This will work on both Microsoft Office SharePoint Server (MOSS) 2007 and Windows SharePoint Services (WSS) 3.0. I think it will also work for previous versions of the mentioned products, but I haven’t tested those.
SPSite yourSite = new SPSite("http://SharePointSite:port");
SPWeb yourWeb = yourSite.OpenWeb();
int nroffiles = yourWeb.Lists["DocumentLibraryYouNeedToEmpty"].ItemCount;
int i = 1;
foreach (SPListItem item in yourWeb.Lists["DocumentLibraryYouNeedToEmpty"].Items)
{
Console.Write("\rdeleting "+i+" of "+nroffiles);
item.File.Delete();
i++;
}
You can also add some code to check if the file you are trying to delete is not checked out. Of course, I wouldn’t recommend running the above code on production environments, for obvious reasons.
d9cf24d5-fbe4-464d-b5ac-96e6e3b069bb|0|.0
Tags: