How to get Content Block from page
Hi
Am trying to write a routine that extracts content blocks from pages for the purposes of creating an XML file to feed another development.
I am stuck on the last 1%. Below is the code I have so far:
PageManager pManager = PageManager.GetManager();
ContentManager contentmanager = ContentManager.GetManager();
PageData page =
null
;
IQueryable<PageNode> nodes = pManager.GetPageNodes().Where(t => t.ApprovalWorkflowState ==
"Published"
);
foreach
(PageNode node
in
nodes)
crap =
""
;
if
(node.Page !=
null
) str += node.Page.Id +
" - "
;
str += node.Title +
"<br />"
;
if
(node.Page !=
null
)
page = node.Page;
//IList<PageControl> controls = page.Controls;
List<ContentBlock> blocks = page.Controls.Where(c=>c.ObjectType==
typeof
(ContentBlock).FullName).Cast<ContentBlock>().ToList();
foreach
(ContentBlock block
in
blocks)
str +=
"<br /><br />"
+ block.Html +
"<br /><br />"
;
(c=>c.ObjectType==
typeof
(ContentBlock).FullName).Cast<ContentBlock>().ToList()" but it fails at runtime stating it cannot cast PageControl to ContentBlock.
Hi Michael,
You should do the following - iterate through the Controls collection of a PageData and then use pManager.LoadControl() for each control and verify the returned result with
var control = pManager.LoadControl(ctrl);
if (control is ContentBlock)