2010-11-17 13 views
15

Dlaczego otrzymuję ten błąd z kodem poniżej ParseException: End of string expected at position 4.Sitecore Szybkie Zapytanie Daje Parse wyjątek

Oto kod: Błąd znajduje się na 3 linii.

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; 

możemy użyć szybkiej kwerendy z SelectSingleItem()? Próbowałem uniknąć sugestii get folder contents and loop through each item until I find the target solution.?

+0

powiązane pytanie: http://stackoverflow.com/questions/3687405/escaping-reserved-words –

+0

Ktoś wie, jak uciec od znaków specjalnych używanych w polach tekstowych, takich jak apostrof w opisie elementu treści? http://stackoverflow.com/questions/16847831/sitecore-fast-query-how-to-search-for-text-containing-special-charples-such – longda

Odpowiedz

7

Jest to błąd, gdy za pomocą szybkiej kwerendy i SelectSingleItem(). Problem został rozwiązany w wydaniu Sitecore CMS 6.3.0 rev.100716. Zobacz Release Notes. Ponieważ używamy 6.2, musiałem przerobić moją metodę, aby użyć kwerendy Sitecore zamiast Szybkiego Zapytania.

+1

Pojawia się, że jest to teraz problem w wersji 6.5.0 (wersja 121009), ale w przypadku zapytania Sitecore (ale w pozycji 5). Radość. – longda

+0

Jest to również problem w Sitecore 6.6, więc jeśli błąd został naprawiony, został ponownie wprowadzony. – dadwithkids

+1

Po napotkaniu tego w wersji 8.1 aktualizacja 3! –

15

Podczas korzystania z kwerendy Sitecore, musisz wymykać nazwy elementów za pomocą myślników. Od 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 potwierdziły, że odnosi się to do szybkiego Query również.

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; 

Ten sam kod działa poprawnie z # ucieka #:

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

Używam Sitecore Fast Query, a nie Sitecore Query. Kreski nie stanowią problemu. –

+0

Czy jesteś pewien? Czy próbowałeś ich uciec? Mój instynkt polegałby na tym, że Szybka kwerenda wykorzystywałaby tę samą logikę analizy, czyniąc kreski wymaganiem. – techphoria414

+0

Zobacz moją aktualizację, dość pewne, że myślniki są problemem. – techphoria414

Powiązane problemy