How to connect file upload control to a button?

I have a button on an HTML page. I want to add a file upload control on this button.

I mean, when the user clicks this button, the file upload control will be the iris, and the selected file will be downloaded.

tell me how can i do this?

+3
source share
4 answers

You want to use the FileUpload control . This MSDN link also contains sample code to show how to save the selected file to the server.

+4
source

", ASP.NET 2.0 FileUpLoad, . , FileUpload Toolbox -. FileUpLoad: "

<asp:FileUpLoad id="FileUpLoad1" runat="server" />

" , Button:"

<asp:Button id="UploadBtn" Text="Upload File" OnClick="UploadBtn_Click" runat="server" Width="105px" />

" , SaveAs FileUpLoad, , ."

protected void UploadBtn_Click(object sender, EventArgs e)
{
if (FileUpLoad1.HasFile)
{

FileUpLoad1.SaveAs(@"C:\temp\" + FileUpLoad1.FileName);
Label1.Text = "File Uploaded: " + FileUpLoad1.FileName ;
}
else
{
Label1.Text = "No File Uploaded.";
}
}

http://asp.net-tutorials.com/controls/file-upload-control/
http://www.wrox.com/WileyCDA/Section/id-292158.html
http://www.c-sharpcorner.com/uploadfile/mahesh/fileupload10092005172118pm/fileupload.aspx

+3

 <input type="file" />

. . - , -.

, QuirksMode .

+1

<asp:FileUpload />. HTML- <input type="file" />

0

Source: https://habr.com/ru/post/1735597/


All Articles