Creating classes for PageTypeBuilder in an existing project

Update: This can now be found on GitHub: https://github.com/eriknordin/PTB-Helpers

While everyone else is creating cool gadgets for the new site center I was appointed to update an “old” site with some new functionality. And since PageTypeBuilder was introduced in my EPiServer life, and don’t feel like working without it in any project. If this would’ve been a small project I would probably just created the PTB classes by hand, but after looking into the page type list I was freaked out. Therefore I spent some time creating a “plugin” (it’s not a  real plugin, just “some” code) that creates PageTypes classes from all the page types and properties in the current project.

Step 1
The first step is to download the source code, it’s a zip-file containing a .aspx/.designer/.cs
Download it here

Step 2
Include the files in your project.

Step 3
Open you web browser and surf to the page.

Step 4
There are a few values that yo can change before doing the import/export (it’s up to you to define what it is :)).
You can add a prefix before and after the class name, change the base class that the classes should extend, enter a namespace (required) and finally decide where to put the files.
ptb-classes1

You can also exclude page types that you don’t want to include.
ptb-classes2

And finally you can decide which namespaces that should be included by default.
ptb-classes3

Step 5
When clicking “Create classes” you will see a log of classes created plus if something is excluded.
An example is that every propertyname with a “-” in it will be excluded because you can’t have “-” in a property name in C#.
When the files are created you just have to include them in your project and you should be good to go. You have to remember to include a reference to PageTypeBuilder, and you also need to change so all PageTypes .aspx.cs files inherits from the right class.

One other thing that should be mentioned is that PageTypes names like “[Something] Page Type Name” will end up like [yout catalog]\Something\PageTypeName.cs (if you don’t have any prefix).

Update – 091103 10:23
1. Discovered a bug and updated the source files.
2. Before using this, backup you database, this code is used without any warranty.
3. If you want to extend the functionality, please feel free to do it.

Update – 100128
DefaultValueType was not set which lead to some problems. Fixed.

20 thoughts on “Creating classes for PageTypeBuilder in an existing project

  1. Petter

    Nice Erik! Will have to try this out. Been thinking about the same issue as you had and now you have (hopefully =)) solved it for me!

  2. Joel Abrahamsson

    Great work Erik! I’ve been planning to do something simillar for quite some time but I have never gotten around to it. Now I don’t have to 🙂

  3. Frederik Vig

    Hi Erik
    Think I found a little bug.. Properties that are not displayed in edit mode don’t get DisplayInEditMode property set to false.

  4. Pablo

    What happens to the page type and it’s associated page instances when you REMOVE a property from the declared page type in code? For example, if I remove “Title” from the class, will the PageTypeBuilder delete the previous property?

  5. Erik Nordin Post author

    Pablo, they won’t be removed. Same thing if you change the property type of a property, it won’t be changed due to possible loss of data.

  6. Lars F

    Very cool util!
    Saved me a lott of time. However I’m wondering why tabs arnt generated using attributes?

  7. Fredrik Evertsson

    A very nice tool, thanks a lot Erik! A little heads up for you who have property-names that contains “å”, “ä” or “ö”, change those to “o” or “a” otherwise you will get a cryptic exception telling you that a property with the name (in my case Sökmotoroptimering) already exists!

  8. Pingback: Generera klasser till PageTypeBuilder från ett redan skapat projekt | Wärting Konsulting - Systemutvecklare

  9. Frederik Vig

    Hi Erik, found a small bug:
    pdf.HelpText.Replace(“\””, “‘”)

    should be:
    pdf.HelpText != null ? pdf.HelpText.Replace(“\””, “‘”) : string.Empty

    Love this tool! 🙂

  10. Jørgen

    Excelent tool.

    A little heads up for you who have set witch page types are to be available to the editor when creating a sub-page under a page type. This setting will not be converted by the tool. It defaults to all pagetypes.

  11. Jonathan Sewell

    Hi Erik, it’d be great to get this on github so it can be forked. I want to add a “select all” link for the check boxes… I only want to import 1 page type out of a list of ~60 and have to check so many boxes manually.

  12. Alf Nilsson

    I’ve made a EPiServer 7 CMS Version of it. Do you want me to commit?

  13. Pingback: Creating Page Type Classes from Page Types in EPiServer CMS 7 | Alf Nilsson talks

  14. LoytMr

    meds tramadol buy tramadol next day delivery recommended dose of tramadol allergic reaction to tramadol symptoms. tramadol for humans dosage tramadol dependence normal dosage for tramadol medical tramadol . tramadol reviews ultram tablets 50 mg . tramadol hcl 50 mg tablet side effects tramadol hydrochloride cheap tramadol overnight delivery tramadol overnight cod 50mg tramadol side effects drugs similar to tramadol

  15. friv 2 online

    Does your site have a contact page? I’m having
    a tough time locating it but, I’d like to send you an e-mail.
    I’ve got some ideas for your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it expand over time.

Leave a Reply

Your email address will not be published. Required fields are marked *