Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |

Wednesday, February 22, 2012

How to: Delete a list programtically

#region DeleteBAEList
 /// 
 /// FUNCTION        : DeleteList
 /// PURPOSE         : To delete the list
 /// PARAMETERS      : currentWeb -> current web
 ///                   strListName -> A string containing the list name
 /// RETURNS         : None
 /// -------------------------------------------------------------------------
 /// 
 public static void DeleteList(SPWeb currentWeb, string strListName)
 {
  try
  {
    currentWeb.AllowUnsafeUpdates = true;
    if (IsListExists(strListName, currentWeb) == true)
    {
      SPList lst = currentWeb.Lists[strListName];
      currentWeb.Lists.Delete(lst.ID);
    }
      currentWeb.AllowUnsafeUpdates = false;
  }
  catch (Exception ex)
  {
    //Error Handling Code
  }
}
#endregion


I already covered in my previous posts about how to check whether the specified lists exist or not? And what/why/where we can use “AllowUnsafeUpdates”. 

Refer to get clear idea on it.

Happy Coding....

No comments:

Post a Comment