Path separators are missing

The issue is that your FileName has single slashes in it. JS will interpret those slashes as escape characters.

The simplest solution is to replace your single slashes with double slashes:

_mainWindow.Browser.ExecuteScriptAsync(
    "document.getElementById('location').value=" + '\''
        + openFileDialog.FileName.Replace(@"\", @"\\") + '\'');

Leave a Comment