Welcome to DetlefGrohs.com Sign in | Join | Help

SPListExists SharePoint 2007 Code Snippet

I use this method whenever I need to determine if a List exists in SharePoint 2007. I have not found a built in method for this yet. I hope there is one, but until I find it, this works. I don't use this in production code, only for deployment and test situations.

    private static bool SPListExists(SPWeb spweb, string listName)
    {
        try
        {
            SPList list = spweb.Lists[listName];
            return true;    // If we get here, we did not get an exception trying to access the list
        }   // there has to be a better way... 
        catch { }   // Do Nothing
        return false;
    } 
Published Saturday, October 06, 2007 8:38 AM by detlef
Filed Under: ,

Comments

No Comments
Anonymous comments are disabled