Front Code:
HTML code
- <asp:fileupload ID="fukeleyi" runat= "server" />
- <asp:button id = "Btnup" Runat = "server" onclick = "Btnup_click" text = " " />
- <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/"); Specify the path to save the uploaded file on the server
- Check that the physical path exists on the server and create if it does not exist
- 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 yet chosen to upload the file!" ;
- }
- }
- }
- }
Asp. NET uploading files using FileUpload