Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Sitecore:使用特定语言访问项目时出现问题_C#_Sitecore_Sitecore7_Sitecore7.2 - Fatal编程技术网

C# Sitecore:使用特定语言访问项目时出现问题

C# Sitecore:使用特定语言访问项目时出现问题,c#,sitecore,sitecore7,sitecore7.2,C#,Sitecore,Sitecore7,Sitecore7.2,我在sitecore中有一个id为“{05B1C498-39D1-40D6-B454-2A3277A6DDF9}”的项目,其中一个语言版本在“en”中,另一个在“da DK”中 对于该项目,有一个字段“Test”,类型为text,在英文版本中,我已在该字段中保存了“English text”。对于上述项目的丹麦版本,我已将“丹麦文本”保存在“Test”字段中 我想用丹麦语获得上述项目的报价。我使用了以下代码: string dicItemId= "{05B1C498-39D1-40D6-B454

我在sitecore中有一个id为“
{05B1C498-39D1-40D6-B454-2A3277A6DDF9}
”的项目,其中一个语言版本在“
en
”中,另一个在“
da DK
”中

对于该项目,有一个字段“
Test
”,类型为
text
,在英文版本中,我已在该字段中保存了“English text”。对于上述项目的丹麦版本,我已将“丹麦文本”保存在“
Test
”字段中

我想用丹麦语获得上述项目的报价。我使用了以下代码:

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

lblTest.Text = dictionaryItem["Test"];
我希望看到上面标签的字符串“Danish Text”。但不知何故,它没有得到丹麦版本,输出的是“英文文本”。

我还尝试使用我的Sitecore中不存在版本的语言获取上述项目的版本,我尝试了:

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

我原以为
字典项
null
,但它仍然包含id为“
{05B1C498-39D1-40D6-B454-2A3277A6DDF9}

的项要进行故障排除,请尝试以下步骤:

  • 确保项目以“da DK”语言发布
  • 该字段不是[共享的]
Context.Database.GetItem(..)将始终返回该项(只要它存在),即使它不包含特定的语言版本

请尝试以下简单测试,以确保以您的语言发布项目:


站点是否使用语言回退?不,该网站没有使用语言回退。远射-您是否尝试发布您的系统/语言/文件夹?@IanGraham是。它已经出版了。几秒钟前,我使用了
contextDatabase.GetItem(dicItemId,Sitecore.Data.Managers.LanguageManager.GetLanguage(“da”)
。现在它成功了。但当我使用“
da DK
”时,它就不起作用了。在Sitecore中,丹麦语言实际上默认名为“da”——这也许可以解释它为什么起作用。。