Search code examples
javascriptc#wpfcefsharp

Path separators are missing


I'm trying to implement the selection of a local file and send its path to js.

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

this option returns a path without delimiters - "PathTofile", although the path itself is written to the file - "Path\To\File". tell me, please, what am I doing wrong?


Solution

  • 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(@"\", @"\\") + '\'');