开发者

Sitecore Fast Query Gives Parse Exception

开发者 https://www.devze.com 2023-01-25 07:16 出处:网络
Why am I getting this error with the code below ParseException: End of string expected at position 4.

Why am I getting this error with the code below ParseException: End of string expected at position 4.

Here's the code: The error is on the 3rd line.

var db = Sitecore.Configuration.Factory.GetDatabase("web");
string query = @"fast:/sitecore/content/foodservice/home/Products/3492-5326/3518-7";
It开发者_StackOverflow社区em item = db.SelectSingleItem(query);
return item;

Can we use a fast query with SelectSingleItem()? I was trying to avoid the get folder contents and loop through each item until I find the target solution. Suggestions?


When using Sitecore Query, you need to escape item names with dashes. From 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#//".

UPDATE: I have confirmed that this applies to Fast Query as well.

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;

The same code runs fine with #escapes#:

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


This is a bug when using Fast Query and SelectSingleItem(). The issue is fixed in the Sitecore CMS 6.3.0 rev.100716 release. See Release Notes. Since we are using 6.2, I had to rewrite my method to use a Sitecore Query instead of the Fast Query.

0

精彩评论

暂无评论...
验证码 换一张
取 消