How to set a value to a file input in HTML?

前端 未结 8 1522
天命终不由人
天命终不由人 2020-11-21 04:45

How can I set the value of this?


相关标签:
8条回答
  • 2020-11-21 05:29

    Actually we can do it. we can set the file value default by using webbrowser control in c# using FormToMultipartPostData Library.We have to download and include this Library in our project. Webbrowser enables the user to navigate Web pages inside form. Once the web page loaded , the script inside the webBrowser1_DocumentCompleted will be executed. So,

    private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
           FormToMultipartPostData postData = 
                new FormToMultipartPostData(webBrowser1, form);
            postData.SetFile("fileField", @"C:\windows\win.ini");
            postData.Submit();
        }
    

    Refer the below link for downloading and complete reference.

    https://www.codeproject.com/Articles/28917/Setting-a-file-to-upload-inside-the-WebBrowser-com

    0 讨论(0)
  • 2020-11-21 05:32

    1) The problem of default value in a file input IS NOT "done for security reasons", but the browsers "just failed to implement it, for no good reason": see this deep report

    2) A simple solution can be to use a text input on top of file input, like here. Of course you need some code to send the file, using now the value in text input and not the file input.

    In my case, doing HTA application, that is not a problem, I don't use form at all.

    0 讨论(0)
提交回复
热议问题