0

I have a software that clicks the button 'Add photo':

private void OpenOpen()
        {

            var elems = webBrowser1.Document.GetElementsByTagName("input");

            foreach (HtmlElement elem in elems)
            {

                if (elem.GetAttribute("type") == "file")
                {

                    elem.InvokeMember("click");
                    break;
                }
            }

After this the file dialog window popups: choose file

The question is: how to set the filepath through this dialogbox? The html code of the button is:

<input type="file" accept="video/*,  video/x-m4v, video/webm, video/x-ms-wmv, video/x-msvideo, video/3gpp, video/flv, video/x-flv, video/mp4, video/quicktime, video/mpeg, video/ogv, image/*" name="composer_photo[]" display="inline" role="button" tabindex="0" class="_n _5f0v" id="js_56">

Thanks a lot

Max
  • 63
  • 1
  • 7

1 Answers1

0

As per my understanding, you need to set a default path. You could try to use the below code:

private void OpenOpen()
    {

        var elems = webBrowser1.Document.GetElementsByTagName("input");

        foreach (HtmlElement elem in elems)
        {

            if (elem.GetAttribute("type") == "file")
            {

                elem.SetAttribute("value", "D:\your_file.txt");
                break;
            }
        }
ROY
  • 63
  • 8
  • Thanks for your reply. But the problem is I can't set the default path without clicking the 'Add file' button. But once the program clicks it, this window appears to be on the top of the page. And here is where the issue is... – Max May 12 '17 at 10:18
  • Updated the Answer. – ROY May 12 '17 at 12:56