Convert page type to another page type programmatically

Vote:
 

Hi,

I know that EPiserver can do this in the admin area. Still we want to enrich the convertion with new data comming from a csv. How we can convert the page type, keeping the current values and then add the new values?

For now the only way is to create the new page type and map all the properties, one by one. 

Do we have a better way?

Thank you

#192376
May 16, 2018 7:50
Vote:
 

The admin plugin uses a static class called PageTypeConverter in the Episerver.Core namespace. You can use this static class to convert the page to the new type then I would suggest just simply using the standard IContentRepository to reload the type after and set the new properties. It's very easy to create an admin plugin so you could create your own version of the page converter if you needed or use the core where required.

#192388
Edited, May 16, 2018 9:46
Vote:
 

The class used from admin mode is EPiServer.Core.PageTypeConverter. It is an "old" class meaning is has no abstraction and so on but just static methods (but it is doing it's job). It has a single method Convert where you can pass in a List<KeyValuePair<int, int>> propertyTypeMap which is basically saying which property that should be mapped to what property. But it only supports data from the original page, there is no way to add external data from outside the original page so it might not be useful for your case.

There is also an event PageTypeConverter.PagesConverted that is raised, but when that is raised the conversion is already done.

#192389
May 16, 2018 9:49
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.