c# - 以编程方式删除 Sitecore 中的子布局

标签 c# .net sitecore sitecore6

有谁知道如何从 Sitecore 项目中删除效果图?

我想删除所有子布局,以便用新的集合替换它们。 我有 tried this但它似乎不起作用。项目没有任何变化。

我好像能得到这样的效果图:

RenderingReference[] renderings = item.Visualization.GetRenderings(Sitecore.Context.Device, true);

但似乎没有办法设置它们。

我也可以得到这样的效果图(从上面的链接):

LayoutDefinition layoutDefinition = LayoutDefinition.Parse(LayoutField.GetFieldValue(item.Fields[Sitecore.FieldIDs.LayoutField]));
DeviceDefinition device = layoutDefinition.GetDevice(Sitecore.Context.Device.ID.ToString());

if (device.Layout != null) device.Layout = null;
if (device.Renderings != null) device.Renderings = new ArrayList();

但这同样行不通。从 layoutDefinition 中清除设备并设置修改后的设备导致此异常:无法建立连接,因为目标机器主动拒绝它。我现在根本无法查看该项目!

我觉得我找错了方向,有什么想法吗?

使用 Sitecore 6.4

更新回复:techphoria414

我试过的代码:

layoutDefinition.Devices.Clear();
layoutDefinition.Devices.Add(device);

最佳答案

我认为你的异常是无关的。要实际保存您的更改,您需要编辑该项目。请确保始终通过 LayoutField.Value 访问和更新值。

LayoutField layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]);
LayoutDefinition layout = LayoutDefinition.Parse(layoutField.Value);
//make your changes to the LayoutDefinition here
item.Editing.BeginEdit();
layoutField.Value = layout.ToXml();
item.Editing.EndEdit();

关于c# - 以编程方式删除 Sitecore 中的子布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9604819/

相关文章:

c# - 使用 Dictionary 和 HashSet 的 GetHashCode 方法

sitecore - 使用存储桶作为 droplink/tree 字段的数据源

.net - LINQ-to-NHibernate 准备好用于生产代码了吗?

c# - 如何从 C# 中的 html 文件中提取 html 链接?

Sitecore 7 ContentSearch - 按随机排序

Sitecore 获得所有父级(祖先),几乎不需要处理(性能)

c# - 如何为 Web 窗体项目中长时间运行的 Ajax 请求禁用/释放早期 session 状态阻塞

c# - XmlSerializer 和表情符号

c# - 如何获取或计算 Azure 文件/共享或服务的大小

c# - 在 FluentEmail 中的后续电子邮件中不断添加收件人