More in this section

Forums / Developing with Sitefinity / Problem with IStagedPage.CopyFromLanguage

Problem with IStagedPage.CopyFromLanguage

3 posts, 0 answered
  1. Michael
    Michael avatar
    15 posts
    Registered:
    11 Jul 2005
    07 Jul 2008
    Link to this post
    Hi,

    I'm trying to create a version of an existing page. Here is some sample code:

    CmsManager cmsManager = new CmsManager();
    ICmsPage cmsPage = (ICmsPage)cmsManager.GetPage(pageID, true);
    cmsPage.Staged.CopyFromLanguage(languageID);
    cmsPage.Staged.CheckIn();
    cmsPage.Publish();

    The code above will create a new version of an existing page, but when I navigate to that page, I'll get a "No template has been selected.". Isn't the method CopyFromLanguage supposed to copy template, theme, and controls?

    Some sample code to create a version of an existing page would be much welcomed. Thanks.
  2. Vlad
    Vlad avatar
    498 posts
    Registered:
    19 Jun 2017
    10 Jul 2008
    Link to this post
    Hi Michael,

    Yes, the CopyFromLanguage method actually copies all content (template, theme, and controls). It seemsin your case it did nothing. Most probably, the problem is that no language version for the specified languageId parameter is found. If you are copying from the default language version, you should provide languageId of the default culture, because invariant culture LCID will not work. Also CopyFromLanguage method updates the the staged object into database, therefore after executing it is not in edit mode anymore. Therefore, before calling CheckIn() you should get the the object again.
    In "code" words:
    int sourceLangID = (languageID == CultureInfo.InvariantCulture.LCID) ? LocalizationManager.DefaultCulture.LCID : languageID; 
    CmsManager cmsManager = new CmsManager(); 
    ICmsPage cmsPage = (ICmsPage)cmsManager.GetPage(pageID, true); 
     
    // Checks out the Cms page creating new staged version 
    IStagedPage staged = cmsPage.Staged.CheckOut(); 
     
    // Copies the content from another language version and saves in into database. 
    staged.CopyFromLanguage(sourceLangID); 
     
    // Gets the page from the database, and checkin (Publish) 
    cmsPage = (ICmsPage)manager.GetPage(pageID, true); 
    cmsPage.Staged.CheckIn(); 
     

    Also, you can see this KB article.

    Hope this will help.

    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Michael
    Michael avatar
    15 posts
    Registered:
    11 Jul 2005
    10 Jul 2008
    Link to this post
    Thanks. Problem solved.
Register for webinar
3 posts, 0 answered