Is there some API utility method which can automatically escape an item path for use in a Sitecore query?
I am building a query string in code which uses an item path. If the item path contains a hyphen or underscore, then that name needs to be escaped in the query (surrounded by #) e.g.
/sitecore/content/my site/home/settings-folder
would need to be escaped to
/sitecore/content/my site/home/#settings folder#
I have code such as:
var query = $"{rootItem.Paths.FullPath}//*[@@templateid='{Templates.MyItemType.TemplateId}']";
var items = db.SelectItems(query);
This fails when the path has a hyphen -
or underscore _
. I've seen this question related to SPE so I could use that regex, but I wonder if there is already some utility method in the Sitecore API to do this?