I need to create a SharePoint Feature, when activated needs to create a Document Library and then enable the manual declaration as record. Following is the code which is working fine in a Console Application but not through Feature.
[Note:- I have been using a Sandbox solution for this purpose]
string ListTitle = "Sample List";
string strRecordCenterURL = "URL";
using (SPSite oSite = new SPSite(strRecordCenterURL))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
SPList oList = oWeb.Lists.TryGetList(ListTitle);
if (oList == null)
{
Guid nKMListGuid = oWeb.Lists.Add(ListTitle, "Description", SPListTemplateType.DocumentLibrary);
oList = oWeb.Lists[nKMListGuid];
oList.OnQuickLaunch = true;
oList.Update();
oWeb.Update();
}
if (oList.RootFolder.Properties.Contains("ecm_IPRListUseListSpecific"))
{
oList.RootFolder.Properties["ecm_IPRListUseListSpecific"] = "True";
}
else
{
oList.RootFolder.Properties.Add("ecm_IPRListUseListSpecific", "True");
}
if (oList.RootFolder.Properties.Contains("ecm_AllowManualDeclaration"))
{
oList.RootFolder.Properties["ecm_AllowManualDeclaration"] = "True";
}
else
{
oList.RootFolder.Properties.Add("ecm_AllowManualDeclaration", "True");
}
oList.RootFolder.Update();
oList.Update();
oWeb.Update();
}
}