How to Delete all items from lists of SharePoint 2010/2007

Often during data migration we need to do clean up list data. I had something similar but there were multiple lists and each list with 5000-10000 records.

Quick console application did the trick of cleaning all the lists.
>> Create a new console application and add reference to Microsoft.SharePoint.dll
>> Use the below code.

Code: [ Applies To : WSS3.0 / Sharepoint 2010 Foundation ]

using System; using Microsoft.SharePoint; using System.Collections.Generic; using System.Text;  namespace SKN.CleanSPLists {     class Program     {         static void Main (string[] args)         {             string webUrl = "http://ws2003";             bool deleteFromRecycleBin = true;             List<string> listNames = new List<string>();             listNames.Add("List Title 1");             listNames.Add("List Title 2");             listNames.Add("List Title 3");             listNames.Add("List Title 4");              using (SPSite site = new SPSite(webUrl))             {                 using (SPWeb web = site.OpenWeb())                 {                     foreach (var listName in listNames)                     {                         SPList list = web.Lists[listName];                          Console.WriteLine("Purging list: " + list.Title);                         Console.WriteLine("Base Type: " + list.BaseType.ToString());                                                   StringBuilder sbDelete = BuildBatchDeleteCommand(list);                         web.ProcessBatchData(sbDelete.ToString());                          Console.WriteLine("Done cleaning list : Presss a key to continue with next list.");  Console.WriteLine("");                         Console.ReadKey();                     }                             if (deleteFromRecycleBin)                     {                        Console.WriteLine("Cleaning Recycle bin");    web.RecycleBin.DeleteAll();                         site.RecycleBin.DeleteAll();                       Console.WriteLine("Done cleaning Recycle bin");                       Console.ReadKey();                     }                                  }             }         }                 /// <summary>         /// Builds a batch string with a list of all the items that are to be deleted.         /// </summary>         /// <param name="spList"></param>         /// <returns></returns>         private static StringBuilder BuildBatchDeleteCommand (SPList spList)         {             StringBuilder sbDelete = new StringBuilder();             sbDelete.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Batch>");             string command = "<Method><SetList Scope=\"Request\">" + spList.ID +                 "</SetList><SetVar Name=\"ID\">{0}</SetVar><SetVar Name=\"Cmd\">Delete</SetVar></Method>";              foreach (SPListItem item in spList.Items)             {                 sbDelete.Append(string.Format(command, item.ID.ToString()));             }             sbDelete.Append("</Batch>");             return sbDelete;         }     } }

How to Hide ribbon except for admin in SharePoint 2010

Client wanted to hide the ribbon from everyone except admin.

1) Open your SharePoint master page
2) Add the following style in head section

<style type="text/css"> #s4-ribbonrow { display : none; }  </style>
3) Now find the start of the "s4-ribbonrow" tag and add following block before this:
<Sharepoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl2" runat="server" PermissionsString="AddAndCustomizePages">     <style type="text/css">         #s4-ribbonrow { display : block; }     </script> </Sharepoint:SPSecurityTrimmedControl>
4) Save the new master page and publish it.