Nick Grattan's Blog

About Microsoft SharePoint, .NET, Natural Language Processing and Machine Learning

SPFolder / SPList: Deleting versus Recycling

with 2 comments

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.

Advertisements

Written by Nick Grattan

October 9, 2007 at 11:13 am

2 Responses

Subscribe to comments with RSS.

  1. The first piece of code will only delete first file in the folder

    Jackie boy

    January 20, 2013 at 6:56 am

  2. […] SPFolder / SPList: Deleting versus Recycling | Nick Grattan’s Blog […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: