How do you set the CodeBehindType property for a Sitefinity Page in C# code?
We are importing a lot of legacy content into Sitefinity, currently we trigger the import via a Sitefinity Page with our custom code in its Code Behind Type option in the Sitefinity editor.
The imported pages are inheriting that CodeBehindType, and we need reset that property during the import.
Thanks for considering my question.
5 Answers, 1 is accepted
As you might know Sitefinity's pages consist of 2 objects - e.g. PageNode (for navigation) and PageData (for presentation). The CodeBehindType property is available from the PageData object of a page:
var pd =
new
PageData();
pd.CodeBehindType =
"Some.Type.Here"
;
You can check our Documentation for detailed CRUD API samples with Pages (both PageNode and PageData objects included) in order to alter your code to fit your requirement.
http://docs.sitefinity.com/for-developers-query-pages
Regards,
Pavel Benov
Telerik

Thank you very much Pavel.
Unfortunately that did not work with the imported content type:
DynamicContent legacyPageContentItem = this.DynamicModuleManager.CreateDataItem(this.LegacyPageContentType);
legacyPageContentItem.CodeBehindType
errors out.
These are not built-in SF pages, but custom content types for pages from the legacy system, and they still call the importing page's code behind when they are previewed, so they re-start the import and delete themselves. They will not display in a page with the widget for listing and display content that the module builder created. that's why I'm trying to clear out that code behind property.
From what I am understanding you have a Sitefinity page, where you have used its CodeBehindType property to set a code behind file. In the code behind file (probably Page_Load event) you are using API to get your legacy content and store it in Sitefinity. Is this assumption correct so far?
In your last reply I can see that you are using DynamicContent type, which is the type used by modules created through Module builder, so I assume you are storing the legacy content into a Dynamic module (from Module builder).
It is important to note here that DynamicContent type does not have CodeBehindType property for it is a model type of object.
Can you tell me on which page have you placed the automatically generated widget for your Dynamic module? If it is placed on the page which you use to import content, please move it to a different page and see if the code is executed again when you preview.
If it still does, then go to Content->Your module->Pages where items like this are published. If the page which you use to import content is at the top of the list with priority 1, move it to the bottom (using the Actions menu).
More information on this can be found here:
http://docs.sitefinity.com/locations-of-content-items-canonical-urls
Regards,
Pavel Benov
Telerik

I am glad I could help.
Regards,
Pavel Benov
Telerik