lon*_*gda 4 .net c# escaping sitecore
也许我是盲人但是我找不到任何关于为Sitecore的快速查询转义特殊字符的文档.
例如,我想在其描述中搜索包含以下文本的内容项:"hot n'chicious"
注意:我尝试过以下转义:
var searchTerm = "hot n'' tasty"; // thought it might need to be escaped for sql
var searchTerm = "#hot n' tasty#"; // this is how you do some other sitecore escaping
var searchTerm = "hot n\' tasty";
Run Code Online (Sandbox Code Playgroud)
示例应用代码:
var searchTerm = "hot n' tasty";
var query = string.Format("fast:/sitecore/content/Home/Products//*[@ContentDescriptionText='%{0}%']", searchTerm);
var items = Database.SelectItems(query);
Run Code Online (Sandbox Code Playgroud)
目前,这给了我一个例外,所以我假设我需要做一些转义:
"]预计在第67位.
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.
异常详细信息:Sitecore.Data.Query.ParseException:"]"预计在第67位.
这是一篇完全正在尝试做的帖子.基本上,您必须使用转义双引号来包装包含引号的字段值.
var searchTerm = "hot n' tasty";
var query = string.Format("fast:/sitecore/content/Home/Products//*[@ContentDescriptionText=\"%{0}%\"]", searchTerm);
var items = Database.SelectItems(query);
Run Code Online (Sandbox Code Playgroud)
编辑:添加链接CoolMcGrr参考逃避快速查询及其限制.. 在这里