Check if a SharePoint list exists

SharePoint 2007 doesn’t have any methods to tell you if a list exists.
So you have to try to get an instance of the list and catch the error.

So here the method I use to check if a list exist.
You pass in the SPListCollection and the title of the lists.

//Check if a list already exists
private static bool listExists(SPListCollection collection, string title)
{
try
{
foreach (SPList list in collection)
{
if (list.Title == title)
{
return true;
}
}
return false;
}
catch (Exception)
{

throw;
}
}

Advertisements

Got something to add?

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