Sitecore 5.2: Copy from one language to another

This piece of code moves all fields from one language to another. It is a sample code, so it is hardcoded to move from danish to swedish. Change the code to use your languages before using it:

void Switch(Sitecore.Data.Items.Item item)
  Sitecore.Data.Items.Item da = Sitecore.Context.ContentDatabase.Items[item.ID, Sitecore.Globalization.Language.Predefined.Danish];
  Sitecore.Data.Items.Item se = Sitecore.Context.ContentDatabase.Items[item.ID, Sitecore.Globalization.Language.Predefined.Swedish];
  foreach (Sitecore.Data.Fields.Field field in da.Fields)
    if ( !field.Shared && !field.Name.StartsWith( "__" ) && field.Name.Trim() != "" )
      se.Fields[field.Name].Value = field.Value;
      field.Value = "";

About briancaos

Developer at Pentia A/S since 2003. Have developed Web Applications using Sitecore Since Sitecore 4.1.
This entry was posted in Sitecore 5 and tagged , , . Bookmark the permalink.

3 Responses to Sitecore 5.2: Copy from one language to another

  1. Lars Nielsen says:

    Hi Brian,

    Good to see some movement on this blog. And good snippet idaa


  2. Sander says:

    Hi Brian,

    Great idea, it doesn’t seem to work for me however. In short, not every item had a version for the ‘new’ language so I created one. Still, changes made in either the source or the destination language item don’t show up. Any help would be appreciated.

    Sander Falise.


  3. Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.