Sometimes we require to check whether SPList exists or not. There is no direct method to check for it. Instead we have to use try-catch block to catch the exception and to determine the list existence:
The code is:
The code is:
using (SPSite ospSite = new SPSite("http://<servername>:<portname>"))
{
using (SPWeb ospWeb = ospSite.OpenWeb())
{
try
{
SPList ospList = ospWeb.Lists["ListName"];
if (ospList != null)
return true;
}
catch(Exception ex)
{
return false;
}
}
}
No comments:
Post a Comment