1

There's an input tag on a website that I want to programmatically upload an image file to. The tag looks like this:

<input type="file" label="upload" ..>

I don't know how to interact with something like this. How would I input a specified image file to that tag?

I have this much:

        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Choose Images";
        ofd.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            HtmlElementCollection elc = wb.Document.GetElementsByTagName("input");
            Image i = Image.FromFile(ofd.FileName);
            foreach (HtmlElement el in elc)
            {
                //Upload file here
            }
        }

3 Answers3

0

You can use: <input type="file" name="pic" accept="image/*"> to filter image files only. For more details you can see: File input 'accept' attribute - is it useful?

Community
  • 1
  • 1
Phong Vo
  • 1,010
  • 7
  • 15
0

The browser won't let you upload a file programatically - that would be a major security issue - you would be able to copy any file from your visitors computer.

The user has to trigger the upload himself- manually.

Ventsyslav Raikov
  • 6,197
  • 1
  • 21
  • 28
0

This may be useful.

WebClient.UploadFile Method

Or maybe this:

Multipart HTTP FILE POST

mathieu
  • 477
  • 3
  • 9