Kamran
Kamran

Reputation: 4100

Sitecore: Problems in accessing an Item in a particular language

I have an Item in sitecore with id '{05B1C498-39D1-40D6-B454-2A3277A6DDF9}' which has one language version in "en" and one in "da-DK" .

For this Item there is a field "Test" with type text, In English version I have saved "English Text" in this field. And for Danish version of above item I have saved "Danish Text" in the field "Test".

I want to get the the above item in Danish language. I used this code:

string dicItemId= "{05B1C498-39D1-40D6-B454-2A3277A6DDF9}"
Item dictionaryItem = Context.Database.GetItem(dicItemId, Sitecore.Data.Managers.LanguageManager.GetLanguage("da-DK"));

lblTest.Text = dictionaryItem["Test"];

I am expecting to see the string "Danish Text" for the above label. But somehow its not getting the Danish version and output is "English Text".

I also tried to get the version of above item in a language whose version does not exist in my Sitecore, I tried with:

Item dictionaryItem = Context.Database.GetItem(dicItemId, Sitecore.Data.Managers.LanguageManager.GetLanguage("nl-NL"));

I was expecting the dictionaryItem as null but still it contains the item with id '{05B1C498-39D1-40D6-B454-2A3277A6DDF9}'

Upvotes: 0

Views: 609

Answers (1)

Konstantin
Konstantin

Reputation: 328

To troubleshoot, try the following steps:

  • Ensure that the Item is published in the "da-DK" language.
  • The field is not [shared]

Context.Database.GetItem(..) will always return the Item (provided it exists), even when it does not include a specific language version.

Try the following simple test to ensure the item in your language is published:

enter image description here

Upvotes: 0

Related Questions