Search code examples
tridion

When using Core Services, how do you Localize or UnLocalize a component without a fatal error when the item is already in that state?


I am using CoreService2010Client, I am iterating through a list of TCM ID values I have and either localizing it or unlocalizing it. Sometimes the item is already localized, so when I call client.Localize();, it throws an exception saying "The item is localized.".

How do I test the state of the component (localized or not-localized) before I try to change it?


Solution

  • First you will need to open a ComponentData object as follows:

    ComponentData usedComponentData = (ComponentData)client.Read(uriUsedItem, new ReadOptions());

    Then check usedComponentData.BluePrintInfo.IsLocalized which will return a Boolean value