ASP. NET uploads files using FileUpload, asp. netfileupload
Front-end code:
Html code
- <Asp: FileUpload ID = "fuKeleyi" runat = "server"/>
- <Asp: Button ID = "BtnUp" runat = "server" onclick = "BtnUp_Click" Text = "Upload"/>
- <Asp: Label ID = "LabMsg" runat = "server"> </asp: Label>
Background C # code:
C # code
- Using System;
- Using System. Collections. Generic;
- Using System. Web;
- Using System. Web. UI;
- Using System. Web. UI. WebControls;
- Namespace docnet
- {
- Public partial class up: System. Web. UI. Page
- {
- Protected void Page_Load (object sender, EventArgs e)
- {
- }
- Protected void BtnUp_Click (object sender, EventArgs e)
- {
- If (fuKeleyi. HasFile)
- {
- String savePath = Server. MapPath ("~ /Hovertreeupload/"); // specifies the storage path of the uploaded file on the server.
- // Check whether the physical path exists on the server. If not, create
- If (! System. IO. Directory. Exists (savePath ))
- {
- System. IO. Directory. CreateDirectory (savePath );
- }
- SavePath = savePath + "\" + fuKeleyi. FileName;
- FuKeleyi. SaveAs (savePath );
- LabMsg. Text = string. Format ("<a href = 'hovertreeupload/{0} '> hovertreeupload/{0} </a>", fuKeleyi. FileName );
- }
- Else
- {
- LabMsg. Text = "You have not selected to upload a file! ";
- }
- }
- }
- }