2010-11-17 90 views
15

为什么会出现这个错误下面ParseException: End of string expected at position 4.Sitecore的快速查询给出了解析异常

下面的代码的代码:该错误是3号线。

var db = Sitecore.Configuration.Factory.GetDatabase("web"); 
string query = @"fast:/sitecore/content/foodservice/home/Products/3492-5326/3518-7"; 
Item item = db.SelectSingleItem(query); 
return item; 

我们可以使用同一个SelectSingleItem()快速查询?我试图避免get folder contents and loop through each item until I find the target solution.建议?

+0

相关问题:http://stackoverflow.com/questions/3687405/escaping-reserved-words – 2011-12-14 05:56:40

+0

任何人都知道如何逃避文本字段中使用的特殊字符,如内容项描述中的撇号? http://stackoverflow.com/questions/16847831/sitecore-fast-query-how-to-search-for-text-containing-special-characters-such – longda 2013-05-31 00:10:52

回答

7

这是一个错误使用快速查询和SelectSingleItem()时。该问题已在Sitecore CMS 6.3.0 rev.100716发行版中修复。见Release Notes。由于我们使用6.2,我不得不重写我的方法使用Sitecore查询,而不是快速查询。

+1

似乎这是6.5.0(修订版121009)中的问题,但是Sitecore查询(但位置5)。喜悦。 – longda 2013-03-21 21:38:35

+0

这也是Sitecore 6.6中的一个问题,所以如果错误得到解决,它就会被重新引入。 – dadwithkids 2014-11-18 19:52:48

+1

刚刚在8.1更新3中遇到过这个! – 2016-09-13 00:10:20

15

使用Sitecore查询时,您需要用破折号转义项目名称。从SDN

Items with dashes in names (“-”) should be included in “#” symbols. Please use such syntax: /sitecore/content/Home/#About-us#. Otherwise you may get the following error: Invalid lookup source "/sitecore/content/TestSiteB/Home/About-us": End of string expected at position 38. Also, an item name should be included in “#” symbols if it contains “and” or “or” word and is used before “//” symbols. For example: "/sitecore/content/Home/#news and events#//".

更新: 我已经证实,这也适用于快速查询为好。

End of string expected at position 27. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Sitecore.Data.Query.ParseException: End of string expected at position 27. 

Source Error: 


Line 21:   protected void Page_Load(object sender, EventArgs e) 
Line 22:   { 
Line 23:    Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/Test-Item"); 
Line 24: 
Line 25:    Model = Sitecore.Context.Item; 

相同的代码运行正常与#逸出#:

Sitecore.Context.Database.SelectSingleItem("fast:/sitecore/Content/Home/#Test-Item#"); 
+0

我正在使用Sitecore快速查询,而不是Sitecore查询。破折号不是问题。 – 2010-11-17 20:50:51

+0

你确定吗?你试过逃脱他们吗?我的直觉是,Fast Query会使用相同的解析逻辑,使得破折号成为一种要求。 – techphoria414 2010-11-20 19:40:53

+0

看到我的更新,相当确定的破折号是问题。 – techphoria414 2010-11-23 04:13:28