我使用xls中的数据以编程方式创建内容树项目节点。 我正面临着将布局与项目节点相关联的问题。 我无法识别我可以使用的项目的任何setter方法。 我想过使用Item.Visualization属性,但它没有帮助。 请有人建议或帮助提供如何以编程方式将布局项目与项目节点相关联的示例代码。
I am programmatically creating content tree item nodes using data in an xls. I am facing issues in associating layout to the item nodes. I am unable to identify any setter method for an item that I can use. I thought of using the Item.Visualization properties but it did not help. Please can someone advice or help with a sample code of how to associate the layout item to the item nodes programmatically.
最满意答案
我理解为什么你很难找到这个,因为它不是很直观。 我已经制作了一些关于如何做的示例代码,并可能稍后写一篇关于它的博客文章。 直到这里是示例代码:
using(new SecurityDisabler()) { Database masterDatabase = Database.GetDatabase("master"); ID sampleLayoutId = new ID("{14030E9F-CE92-49C6-AD87-7D49B50E42EA}"); ID defaultDeviceId = new ID("{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}"); ID sampleItemId = new ID("{2E4C98CF-DD72-4B55-9DF6-2F6691A6690B}"); ID sampleRenderingId = new ID("{493B3A83-0FA7-4484-8FC9-4680991CF743}"); Item sampleItem = masterDatabase.GetItem(sampleItemId); Item layoutItem = masterDatabase.GetItem(sampleLayoutId); LayoutDefinition layoutDefinition = new LayoutDefinition(); layoutDefinition.LoadXml(sampleItem["__Renderings"]); DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(defaultDeviceId.ToString()); deviceDefinition.ID = defaultDeviceId.ToString(); deviceDefinition.Layout = sampleLayoutId.ToString(); RenderingDefinition renderingDefinition = new RenderingDefinition(); renderingDefinition.ItemID = sampleRenderingId.ToString(); deviceDefinition.AddRendering(renderingDefinition); sampleItem.Editing.BeginEdit(); sampleItem["__Renderings"] = layoutDefinition.ToXml(); sampleItem.Editing.EndEdit(); }我希望你能从中理解,否则当我有时间写博客文章时,它会更具说明性。
I understand why you are finding this hard, as it isn't very intuitive. I have made some sample code on how to do it and will probably write up a blog post about it later. Untill then here is the sample code:
using(new SecurityDisabler()) { Database masterDatabase = Database.GetDatabase("master"); ID sampleLayoutId = new ID("{14030E9F-CE92-49C6-AD87-7D49B50E42EA}"); ID defaultDeviceId = new ID("{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}"); ID sampleItemId = new ID("{2E4C98CF-DD72-4B55-9DF6-2F6691A6690B}"); ID sampleRenderingId = new ID("{493B3A83-0FA7-4484-8FC9-4680991CF743}"); Item sampleItem = masterDatabase.GetItem(sampleItemId); Item layoutItem = masterDatabase.GetItem(sampleLayoutId); LayoutDefinition layoutDefinition = new LayoutDefinition(); layoutDefinition.LoadXml(sampleItem["__Renderings"]); DeviceDefinition deviceDefinition = layoutDefinition.GetDevice(defaultDeviceId.ToString()); deviceDefinition.ID = defaultDeviceId.ToString(); deviceDefinition.Layout = sampleLayoutId.ToString(); RenderingDefinition renderingDefinition = new RenderingDefinition(); renderingDefinition.ItemID = sampleRenderingId.ToString(); deviceDefinition.AddRendering(renderingDefinition); sampleItem.Editing.BeginEdit(); sampleItem["__Renderings"] = layoutDefinition.ToXml(); sampleItem.Editing.EndEdit(); }I hope you can make sense from that, otherwise it will be more explanatory, when I get time to write the blog post.
更多推荐
发布评论