我有一个自定义网站模板,它使用事件接收器激活一个功能,接收器唯一做的就是激活其他一些功能,所有功能都在同一个接收器中。
我激活的第一个功能是名为“Audits”的ListTemplate。 在我激活的第三个功能中,我尝试通过对象模型使用该模板,但是找不到它,因此它会引发异常。
我尝试使用web.Update()
更新网站,但这也无效。
当代码通过网站模板激活时,代码不起作用,这意味着,如果我从已创建的网站激活我的功能,它可以正常工作。
创建网站时有没有办法访问ListTemplate?
提前致谢
编辑:这是主要功能
/// <summary>
/// Evento disparado al activar la feature
/// </summary>
/// <param name="properties"></param>
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
//Obteniendo el sitio (web) en donde fue activada la feature
SPWeb web = (SPWeb)properties.Feature.Parent;
//Guid a utilizar para instalar las features
Guid g;
//GUID de Feature de list template de auditorías
g = new Guid("{3b91e461-e8c9-49dd-857a-671eb031017c}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature Catalogos
g = new Guid("{d102dd61-0aaf-4a18-8bcc-2260e78cc87c}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature Content type de auditorías
g = new Guid("{a5c3defb-bcbf-41e5-aefc-2617814d25d6}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature CheckList template
g = new Guid("{63fa11ba-e8e2-414d-bb7e-a3cdbce11cfe}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature asocia eventos
g = new Guid("{bbc32500-034d-4d9e-a048-558d62edfe53}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature para crear preguntas
g = new Guid("{ee66eb41-57a4-400a-9c50-8db0e6beeb80}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature para ECB
g = new Guid("{9bbdb06c-4ea1-4328-8b3d-828ea2043d3e}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature para hallazgos
g = new Guid("{acfdda27-58d5-4f7e-a6de-0a7fe190bc74}");
if (web.Features[g] == null)
web.Features.Add(g);
//GUID de Feature para resultados
g = new Guid("{a9a804dd-18a3-47a0-80bf-25e785a8cac8}");
if (web.Features[g] == null)
web.Features.Add(g);
}
第一个功能是列表模板。 第三个功能有一个接收器,我在其中寻找模板
//Obteniendo el template
SPListTemplate ltAuditorias = sitio.ListTemplates["Auditoria"];
但是,我得到一个超出范围异常的索引,因为找不到它。 正如我所说,只有通过Feature标记中的网站模板激活主要功能时才会发生这种情况。 如果我创建一个空白站点,然后激活主要功能,一切正常。
由于
答案 0 :(得分:0)
您的网站可能在您的功能接收器被触发时未完全配置。这意味着并非所有网站元素(例如列表模板)都可用。 作为解决方法,您可以实施provisioning provider。
SPWebProvisioningProvider允许您控制您正在配置的SPWeb(网站)或SPSite(网站集)。您可以将自己的自定义代码添加到解决方案中,而不仅仅使用站点模板和可以通过站点模板应用的更改。