Nick Grattan's Blog

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

Document Libraries: SPList and SPFolder.Delete Differences

with one comment

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++)

{

    spList.Items[0].Delete();

}

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++)

{

    spFolder.Files[0].Delete();

}

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

One Response

Subscribe to comments with RSS.

  1. […] And to https://nickgrattan.wordpress.com/2007/10/09/document-libraries-splist-an… […]


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: