I have a SharePoint timer job that requires a configuration list to exist at a specific location in a site collection. If this list does not exist, I want to indicate this to the user so that they can create (and fill, of course) the specified list and repeat the task .
I can write to the event log with the code below, and I know that I can throw an exception to indicate the status of the failed operation, but I want to make an exception with a message that indicates the problem in a way that does not require viewing the ULS or accessing the Event Log . The posts I have found so far like this and this one , t have too many details.
So, two questions: 1) Is there a way to provide an error message to exclude the timer job? 2) Is there a better choice for throwing than Exception ()?
Event logging used when a site collection is missing
SPDiagnosticsService.Local.WriteEvent(0,
new SPDiagnosticsCategory("MyCategory",
TraceSeverity.Unexpected,
EventSeverity.ErrorCritical),
EventSeverity.ErrorCritical,
"Assert failed: if (!spweb.Exists)" + sp.Url,
sp.ToString());
What I would like to do with the missing configuration list
bool configListExists = ListExists(spweb, ConfigListName);
if (! configListExists)
{
ReportMissingConfigList();
throw new Exception("Configuration list not found");
}
public static bool ListExists(SPWeb web, string listName)
{
return web.Lists.Cast<SPList>().Any(list => string.Equals(list.Title, listName));
}
source
share