I have created timer job and in Execute
method of job i have below code which create list
using (SPSite oSPsite = new SPSite("http://myurl"))
{
oSPsite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = oSPsite.OpenWeb())
{
oSPWeb.AllowUnsafeUpdates = true;
/* 1. create list from custom ListTemplate present within ListTemplateGalery */
SPListTemplateCollection lstTemp = oSPsite.GetCustomListTemplates(oSPWeb);
SPListTemplate template = lstTemp["MyTaskList"];
oSPWeb.Lists.Add("List Name", "Description", template);
/* 2. create list from sharepoint list content type (e.g. Links) */
oSPWeb.Lists.Add("List Name", "Description", SPListTemplateType.Links);
oSPWeb.AllowUnsafeUpdates = false;
}
oSPsite.AllowUnsafeUpdates = false;
}
When i debug i get error on this line
SPListTemplate template = lstTemp["MyTaskList"];
The error is value does not fall within expected range
What could be reason of error? I have also tried to increase value of List View Lookup Threshold
to 800 which is under central administration. But nothing is working.