I'm developing a windows desktop application with c#/.net and want to add a feature to open windows explorer and search a query in the computer from the application.
I plan to use Windows search protocol to implement it. Below is my code snippet. The rawQuery is passed from my application to the windows explorer search box.
var query = "&query=" + HttpUtility.UrlEncode(rawQuery);
var location = string.Empty;
foreach (var drive in DriveInfo.GetDrives().Where(d => d.IsReady && d.DriveType.Equals(DriveType.Fixed)))
{
location += "&crumb=location:" + HttpUtility.UrlEncode(drive.Name);
}
var searchQuery = "search:displayname=Search computer" + query + location;
Process.Start(searchQuery);
Above code has an issue. If the rawQuery has non English character, it is shown incorrectly in windows explorer search box after it's encoded(HttpUtility.UrlEncode()). For example, if rawQuery is Chinese, like "微软", it searches 微软 in windows explorer. It's bad.
However, if rawQuery is not encoded, special characters, like &, %, etc., cannot be shown in windows explorer search box.
So I'm not sure how to determine if the character should be encoded or not. I did not find any documentation about that in search protocol spec.
Does anybody know which characters should be encoded?