Nick Grattan’s SharePoint Blog

About Microsoft SharePoint and some .NET

SPFolder / SPList: Deleting versus Recycling

leave a comment »

The following code shows how to remove all documents from a folder:

int iCount = spFolder.Files.Count;

for (int i = 0; i < iCount; i++)

{

    spFolder.Files[0].Delete();

}

Deleting documents with this code will delete permanently without using the recycle bin. To move the document to the recycle bin use the following code:

spFolder.Files[0].Recycle();

The SPItem class has a Recycle method as well as a Delete method and can be used in a similar way.

Written by Nick Grattan

October 9, 2007 at 11:13 am

Leave a Reply