More in this section

Forums / Developing with Sitefinity / GetTemplate: Casting to PageTemplate

GetTemplate: Casting to PageTemplate

4 posts, 0 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    17 Jun 2008
    Link to this post
    I'm using the example found in "Working with Pages" in the Developers Manual and it throws an exception:

    Unable to cast object of type 'Telerik.Cms.Data.CmsTemplateContent' to type 'Telerik.Cms.Data.PageTemplate'.

    The sample code wasn't usable as-is, so I had to guess at a couple of things:

     

    // create user's page

    CmsManager manager = new CmsManager();

    ICmsPage userPage = manager.CreatePage("Del Taco");

    userPage.Navigable = true;

    userPage.MenuName = "Del";


    // This works. The userPage.Parent property is populated afterward

    userPage.ParentID = ((ICmsPage)manager.GetPages()[0]).ID;


    // Exception here. Correct format for identifying template?

    userPage.Staged.Template = manager.GetTemplate("Default");


    userPage.Publish();


    What do you pass for the string value of GetTemplate()?

    I've tried passing the name in the GUI ("Default") and passing master page file name ("Default.master"). Both raise the exception. Same with "CommunityMain"


    I appreciate any pointers. This is the first snippet of code I've run against the API.
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    17 Jun 2008
    Link to this post
    Hi Jeff,

    Please try to modify the line that generates the error as follows:

    Telerik.Cms.Data.PageTemplate template = ((Telerik.Cms.Data.CmsTemplateContent)manager.GetTemplate("Default")).PageTemplate; 
    userPage.Staged.Template = template; 

    Also, you can find useful information on this matter in the following forum thread.

    Do let us know if you need any further assistance.

    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    17 Jun 2008
    Link to this post

    Thanks for the reply. I will try it tonight.

    Two follow-ups:

    1. I'm "not authorized" to access the forum thread link you gave me for more info:

    HTTP Error 403.6 - Forbidden: IP address of the client has been rejected.


    2. When these glaring errors in documentation are pointed out to you, how quickly are they fixed?

    Apparently this is a known documentation issue that would take minimal effort to fix. As it is now, people like me reading it for the first time bang their head for an hour trying to figure out a solution, then waste your time rehashing an old issue.

    I'm still evaluating this product (Standard, not Community) and this is a not a good first impression.

  4. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    18 Jun 2008
    Link to this post
    FYI, tested it out and it works like a charm! Thanks for your prompt help.
Register for webinar
4 posts, 0 answered