Can't create PageTemplate - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Can't create PageTemplate

  • Can't create PageTemplate
  • Hello,

    I'm trying to use the API to create PageTemplates from code but I ran into a problem. After creating a page manager with

    m_PageManager = PageManager.GetManager();
    I get a valid reference but then when I call

    PageTemplate template = m_PageManager.CreateTemplate();

    I get the following exception:

    System.UnauthorizedAccessException: You are not authorized to 'Create 0' ('PageTemplates').
       at DynamicModule.ns.Wrapped_OpenAccessPageProvider_4cd78ae30c8f42e0b41029957c79c297.CreateTemplate()
       at Telerik.Sitefinity.Modules.Pages.PageManager.CreateTemplate()
       at ............ :line 57

    The following two lines execute without problem

    PageData pageData = m_PageManager.CreatePageData();
    PageNode pageNode = m_PageManager.CreatePageNode();

    Any ideas what could be wrong when creating templates and maybe a small example on how to create one and use it with a page?

    Best regards,
  • Hi Lupi,

    You are getting the error, because you are not logged in and you are trying to create a new template with an anonymous user. You have to grant "Anonymous" user "Create" permissions or suppress the security check.

    var manager = PageManager.GetManager();
    manager.Provider.SuppressSecurityChecks = true;
    var template =  manager.CreateTemplate(new Guid("DB253C06-DF25-42b3-8BF7-2CE022E53121"));
    template.Name = "SampleTemplate2";
    template.Title = "SampleTemplate2";

    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • Hello

    Thanks, that worked for other content managers as well. Now I found possibly an issue - when calling

    var checkNews = newsManager.GetNewsItem(id);

    where id is some Guid I get this exception:

    Telerik.OpenAccess.Exceptions.NoSuchObjectException: No row for Telerik.Sitefinity.News.Model.NewsItem ('sf_news_items') GenericOID@c54d4ae0 NewsItem content_id=e74a0fec-0607-450c-81ce-24eb1df3c676 NOTRES
       at DynamicModule.ns.Wrapped_OpenAccessNewsProvider_3986aa31ddb24962bfe5c86a5a0b89c0.GetNewsItem(Guid id)
       at Telerik.Sitefinity.Modules.News.NewsManager.GetNewsItem(Guid id)
       at ....

  • Hello Lupi,

    Try using the code below.

    var item = App.WorkWith().NewsItem().ContentManager.GetItem(typeof(NewsItem), new Guid("76CFAEBD-E2BB-40B5-9670-C10C565B7830"));

    Make sure that you are passing the correct id . You can make an query to the database - SELECT * FROM [DB NAME].[dbo].[sf_news_items]

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  • Thanks for the reply. I used the following code and it worked for me:

    var items = newsManager.GetNewsItems().Where(t => t.Title == title && t.PublicationDate == publicationDate);
    if (items.Count() > 0)


    Guid id = new Guid(<my_source_guid>);
    var items = newsManager.GetNewsItems().Where(t => t.Id == id);
    if (items.Count() > 0)