Nick Grattan's Blog

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

Document Libraries: SPList and SPFolder.Delete Differences

with 2 comments

Removing items from a document library can be done in two different ways. Firstly, using SPList.Delete:

int iCount = spList.Items.Count;

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




This code will delete all the items/documents in all folders, but will leave the folders undeleted. Alternatively, you may write:

int iCount = spFolder.Files.Count;

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




This will delete the items/documents only in the folder represented by ‘spFolder’, and items/documents in other sub-folders will remain. The references to spList and spFolder can be obtained like this:

spList = currentWeb.Lists[“MyDocumentLibrary”];

spFolder = currentWeb.Folders[“MyDocumentLibrary”];

In this case, spFolder refers to the root folder in the document library.









Written by Nick Grattan

October 9, 2007 at 11:43 am

2 Responses

Subscribe to comments with RSS.

  1. […] And to… […]

  2. […] Document Libraries: SPList and SPFolder.Delete Differences | Nick Grattan’s Blog […]

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: