以编程方式枚举发布页面布局的 Web 部件区域
我遇到的情况是,我的类传递了 PublishingPage 实例,并且我想枚举此页面的布局页面中使用的所有 Web 部件区域。
事实证明这很困难。
PublishingPage 有一个名为 Layout 的属性,其类型为 PageLayout。这与 PublishingLayoutPage 不同,PublishingLayoutPage 继承(最终)到具有 Zones 属性的 Page。此 PageLayout 类型没有对具有我需要的 Zones 属性的普通 ASP.NET 页面类型的任何引用。
我可以从 PublishingPage.Layout 属性获取 SPListItem 和 SPFile,并以原始文本形式获取页面布局的内容,但这无法使用 XmlReader 进行解析,因为它不是有效的 XML(具有 <% 标签,这些标签是无效的)。
我可以从 PublishingPage.ListItem.Web 获取 SPWeb,这可以获取 SPLimitedWebPartManager,在其中我可以获取 LimitedWebParts 的集合(其中包含区域信息) - 但这不会有帮助,因为在我的代码的这个阶段,我有没有网络部件。
我很困惑,看起来发布基础设施与 ASP.NET 和 SharePoint 完全分离。
更新:
我可以使用 SPLimitedWebPartManager 将虚拟 Web 部件(如新的 ContentEditorWebPart)添加到 Web 部件区域(我有所使用的区域的名称),但是当我保存它时并重新检查页面(并获取新的 SPLWPM),我可以取回 WebPart,但 Zone 属性为 null(ZoneID 属性已填充且正确)。
I have a situation where a class I have is passed a PublishingPage instance and I want to enumerate any and all web part zones that are used in the Layout Page for this page.
This is proving tough.
PublishingPage has a property called Layout, which is of type PageLayout. This is different from PublishingLayoutPage which inherits (eventually) to Page which has the Zones property. This PageLayout type does not have any reference to the normal ASP.NET Page type which has the Zones property I need.
I can get an SPListItem and a SPFile from the PublishingPage.Layout property, and get the contents of the page layout in raw text form, but this can't be parsed with XmlReader as it's not valid XML (has <% tags which are invalid).
I can get an SPWeb from PublishingPage.ListItem.Web, and this can get me an SPLimitedWebPartManager, where I can get a collection of LimitedWebParts (which has Zone information) - but this won't help because at this stage of my code I have no web parts.
I'm pretty stuck, it looks like the Publishing Infrastructure is quite detached from both ASP.NET and SharePoint.
UPDATE:
I can use the SPLimitedWebPartManager to add a dummy web part (like a new ContentEditorWebPart) to a web part zone (I have the names of the zones that are used), but when I save this out and check the page back in (and get a new SPLWPM), I can get the WebParts back but the Zone property is null (the ZoneID property is populated and correct).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Wayne Fan 在 上发布的帖子该线程似乎涵盖了您想要做的事情。希望这有帮助。
The posts from Wayne Fan on this thread seem to cover what you're trying to do. Hope this helps.