Donate

Syntax error, '>' expected in Sitecore CMS

When I was a developer in a large corporation before, I was assigned to a Sitecore CMS project. While working on the CMS's services in getting the contents, I encountered an error as mentioned in a title post.

After doing some research, I found out that the CMS's parser does not recognize special characters of the data returned from it's search query.

So the workaround that I found from an article was to surround the data returned with hash tags.
In the sample codes below, I just added a snippet to insert hashtags to data returned from the parser.

Sample Data Returned: Tel-Aviv
Formatted data: #Tel-Aviv#

Original method:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
public static IEnumerable<IUniversity> GetSchoolsByState(Guid stateProvinceId, Language languageVersion)
{
    if (stateProvinceId.Equals(Guid.Empty))
        return null;
 
    var stateProvinceReferenceItem = Context.Database.GetItem(ID.Parse(stateProvinceId));
    if (stateProvinceReferenceItem == null)
        return null;
        
    return GetSchoolsByStateProvince(stateProvinceReferenceItem.Paths.Path, languageVersion);
}

Modified Method:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
public static IEnumerable<IUniversity> GetSchoolsByState(Guid stateProvinceId, Language languageVersion)
{
    if (stateProvinceId.Equals(Guid.Empty))
        return null;
 
    var stateProvinceReferenceItem = Context.Database.GetItem(ID.Parse(stateProvinceId));
    if (stateProvinceReferenceItem == null)
        return null;
                
    //added code fix
    var path = stateProvinceReferenceItem.Paths.Path;
    if (path.Substring(path.LastIndexOf("/", StringComparison.Ordinal)).Split(new string[] { "-" }, 
          StringSplitOptions.RemoveEmptyEntries).Length > 1)
    {
        path = path.Insert(path.LastIndexOf("/", StringComparison.Ordinal) + 1, "#");
        path = path.Insert(path.Length, "#");
        return GetSchoolsByStateProvince(path, languageVersion);
    }         
    
    return GetSchoolsByStateProvince(stateProvinceReferenceItem.Paths.Path, languageVersion);
}

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid