+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / How can I programmatically copy shared content items to other languages?

How can I programmatically copy shared content items to other languages?

4 posts, 0 answered
  1. Wakefly
    Wakefly avatar
    11 posts
    Registered:
    21 Sep 2006
    26 May 2009
    Link to this post
    I have a multilingual site setup, and I would like to take all of my English shared content and copy it to the other languages.

    I tried something like this, but I'm not sure if I'm doing it right:

    private static void CopyContentItemToLanguage(IContent existingContent, CultureInfo culture) 
        { 
            IContent newContent = _manager.CreateContent(existingContent.MimeType); 
     
            newContent.ParentID = existingContent.ParentID; 
            newContent.Status = existingContent.Status; 
            newContent.Content = existingContent.Content; 
            newContent.Language = culture.DisplayName; 
     
            _manager.SaveContent(newContent); 
        } 

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 May 2009
    Link to this post
    Hello Wakefly,

    I regret to inform you that there is no method that will allow you to get all content items that have been shared. You can get the items, but you do not know which of them are shared.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Wakefly
    Wakefly avatar
    11 posts
    Registered:
    21 Sep 2006
    27 May 2009
    Link to this post
    But SiteFinity knows which content is shared, right?  So there must be a way, even if its hidden from the API?  Do you know what that might be?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    27 May 2009
    Link to this post
    Hi Wakefly,

    All content items that you have in your module are considered as "Shared Content". The content directly created in Generic Content Control is not shared and it does not exists as content item in Generic Content module.

    Below is a code that will copy all items you have in Generic Content module to all other languages you have defined in your web.config file.

         ContentManager manager = new ContentManager("Generic_Content"); 
            IList listofContentItems = manager.GetContent(); 
            foreach (IContent source in listofContentItems) 
            { 
                if (source != null && LocalizationManager.IsDefaultCulture) 
                { 
                    CultureInfo backupCulture = System.Threading.Thread.CurrentThread.CurrentUICulture; 
                    string originalContent = source.Content.ToString(); 
                    string sourceCulture = source.Language; 
     
                    foreach (KeyValuePair<string, CultureInfo> pair in Telerik.Localization.LocalizationManager.Cultures) 
                    { 
                        System.Threading.Thread.CurrentThread.CurrentUICulture = pair.Value; 
                        IContent target = manager.GetStagedContent(source.ID); 
                        if (!string.IsNullOrEmpty(target.Content.ToString())) 
                            continue
     
                        target.Content = string.Format( 
                            "Translate {0} to {1}.", originalContent, pair.Key); 
                        manager.SaveContent(target); 
                    } 
                    System.Threading.Thread.CurrentThread.CurrentUICulture = backupCulture; 
                } 
            } 


    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered