I want to search for a Sharepoint Site with the string "My_Site" in it - with an underscore. This fails with an error that says that the underscore character is not valid.
My code looks like this:
var sites = await graph.Sites.GetAsync((config) =>
{
config.QueryParameters.Select = new string[] { "name", "webUrl", "id" };
config.QueryParameters.Search = "My_Site";
});
If I remove the underscore - the error disappears.
How can I add an underscore to a Microsoft Graph search?
You need to use double quotes for the search query parameter:
var sites = await graph.Sites.GetAsync((config) =>
{
config.QueryParameters.Select = new string[] { "name", "webUrl", "id" };
config.QueryParameters.Search = "\"My_Site\"";
});