How To Clear a List in SharePoint

Posted: April 4, 2010 in Development
Tags: ,
This is the code you can use :


    private static void ClearList(SPList listToClear)

    {

        int initialItemCount = listToClear.Items.Count;

         for (int counter = 0; counter < initialItemCount; counter++)

        {

            // Always delete the list item at index 0

            SPListItem listItemToClear = listToClear.Items[0];

            listItemToClear.Delete();

        }

        listToClear.Update();

    }
Advertisements

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