Try our conversational search powered by Generative AI!

Copying of page properties

Vote:
 

I'm trying to copy a page with all its properties to a new language branch. Both CreateWritableClone and Createlanguagebranch don't copy the page properties. Is this possible?

#35505
Dec 14, 2009 13:10
Vote:
 

Hi!

Here is some sample code that does a property for property copy from the current language to the hard coded language branch "SV". You can probably modify the code to fit your needs:

           
LanguageSelector selector = new LanguageSelector("SV");
PageData newLanguage = DataFactory.Instance.CreateLanguageBranch(CurrentPageLink, selector);
foreach (PropertyData property in CurrentPage.Property)
{
    if (!property.IsLanguageSpecific || property.IsMetaData)
    {
        continue;
    }
    newLanguage[property.Name] = property.Value;
}
newLanguage.PageName =
    CurrentPage.PageName + "- copy";
DataFactory.Instance.Save(newLanguage, SaveAction.Publish);

 

Regards
Linus Ekström
EPiServer Development Team

            LanguageSelector selector = new LanguageSelector("SV");
            PageData newLanguage = DataFactory.Instance.CreateLanguageBranch(CurrentPageLink, selector);
            foreach (PropertyData property in CurrentPage.Property)
            {
                if (!property.IsLanguageSpecific || property.IsMetaData)
                {
                    continue;
                }
                newLanguage[property.Name] = property.Value;
            }
            newLanguage.PageName =
                CurrentPage.PageName + "- copy";
            DataFactory.Instance.Save(newLanguage, SaveActi
            LanguageSelector selector = new LanguageSelector("SV");
            PageData newLanguage = DataFactory.Instance.CreateLanguageBranch(CurrentPageLink, selector);
            foreach (PropertyData property in CurrentPage.Property)
            {
                if (!property.IsLanguageSpecific || property.IsMetaData)
                {
                    continue;
                }
                newLanguage[property.Name] = property.Value;
            }
            newLanguage.PageName =
                CurrentPage.PageName + "- copy";
            DataFactory.Instance.Save(newLanguage, SaveAction.Publish);
on.Publish);
#35521
Dec 14, 2009 18:31
Vote:
 

Works like a dream, thank Linus.

#35530
Dec 15, 2009 9:43
* 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.