During one of my project i came accross this situation many time when i had to check whether list or document library already exists or not. So here is the solution
To check document/picture library there is an existing method which can be used like below
if (!web.GetFolder(strName).Exists)
{
      ......
}
Here 'strName' is the name of document/picture library.
But for list this method does not work. Unfortunately there is no method to check if list exists so we need to do a trick for that, check out below
SPList list = null;
try 
{ 
   list = web.Lists[strListTitle];
}
catch { }
if (list == null)
{
   .....
Cheers.
 
No comments:
Post a Comment