Click here to Skip to main content
15,886,110 members
Articles / Programming Languages / C#
Tip/Trick

Squadron Empty List Add-in

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
26 Nov 2012CPOL2 min read 6.3K   3  
A new add-in inside the Squadron for SharePoint 2010 tool.

Introduction

In this article we can explore a new add-in inside the Squadron for SharePoint 2010 tool.

Empty List Addin

The Empty List add-in can be applied for:

  1. Lists
  2. Libraries

The add-in performs the following:

  1. Empty the list or library by deleting all items
  2. Delete the list or library

The add-in is a quick utility as it helps in one click emptying/deleting of multiple lists/libraries.

Squadron is a SharePoint 2010 tool containing multiple add-ins. You can download the tool freely from CodePlex using the following URL: http://squadron2010.codeplex.com/.

Image 1

After downloading and installing, you can run the Squadron tool from Start menu > Squadron.

Image 2

EMPTY Operation

Click on the Empty List item from the left pane. You will get the following screen with Lists and Libraries listed.

Image 3

The Lists and Libraries are selected based on the URL, hidden properties. You can change the URL from the URL text box given.

Now we are going to perform the EMPTY operation. Please note that all the entries in the selected lists will be deleted. You can manually select the list/library to perform the EMPTY operation.

To select all the lists/libraries, use the context menu associated to Check All / Uncheck All.

Image 4

After selecting the list, click on the Empty Selected button from the right hand side.

Image 5

Please note that the selected Tasks list contains the following data before the operation.

Image 6

On clicking the Empty Selected button, you will get the following prompt.

Image 7

You can click the Yes button to continue if you are sure about deleting all items in the selected list. Now returning to the SharePoint list, you can see the items are deleted.

Image 8

This concludes our EMPTY operation.

The Show Count check box shows the item count of each list or library.

The Show Hidden check box shows the hidden lists and libraries (including Quick Launch, System).

Image 9

DELETE Operation

Now we can try the DELETE operation. Please note that the DELETE operation deletes the selected lists and libraries. For performing this operation I prefer you use a temporary site with lists and libraries.

Image 10

After selecting the items, click the Delete Selected button. You will get the following confirmation dialog.

Image 11

On confirming yes, the selected items are deleted. You will see the items missing in the next refresh.

Image 12

Code

Following is the code for an EMTPY operation.

C#
private void PerformEmpty()
{
    using (SPSite site = new SPSite(SquadronContext.Url, SquadronContext.GetUserToken()))
    {
        using (SPWeb web = site.OpenWeb())
        {
            foreach (string title in NameList.CheckedItems)
            {
                SPList list = web.Lists[title];
                int count = list.Items.Count;

                for (int x = list.Items.Count - 1; x >= 0; x--)
                {
                    list.Items[x].Delete();
                }
                SquadronContext.WriteMessage(title + 
                  " EMPTY performed by deleting " + count.ToString() + " items");
            }
        }
    }
    SquadronContext.WriteMessage("Performed Empty operations.");
}

Following is the code for a DELETE operation.

C#
private void PerformDelete()
{
    using (SPSite site = new SPSite(SquadronContext.Url))
    {
        using (SPWeb web = site.OpenWeb())
        {
            foreach (string title in NameList.CheckedItems)
            {
                SPList list = web.Lists[title];

                try
                {
                    list.Delete();
                    SquadronContext.WriteMessage(title + " DELETE done.");
                }
                catch (Exception ex)
                {
                    SquadronContext.WriteMessage("DELETE Exception for " + title + " " + ex.ToString());
                }
            }
        }
    }
    SquadronContext.WriteMessage("Performed DELETE operations.");
    RefreshList();
}

References

http://squadron2010.codeplex.com/

Summary

In this article we have explored the EMPTY and DELETE operations of the Squadron for SharePoint 2010 tool. I repeat that this tool is free for use and in the long run there should be more and more utilities incorporated.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Jean Paul is a Microsoft MVP and Architect with 12+ years of experience. He is very much passionate in programming and his core skills are SharePoint, ASP.NET & C#.

In the academic side he do hold a BS in Computer Science & MBA. In the certification side he holds MCPD & MCTS spanning from .Net Fundamentals to SQL Server.

Most of the free time he will be doing technical activities like researching solutions, writing articles, resolving forum problems etc. He believes quality & satisfaction goes hand in hand.

You can find some of his work over here. He blogs at http://jeanpaulva.com

Comments and Discussions

 
-- There are no messages in this forum --