FileUpload Control
How to Upload a file in an ASP.NET website…???
Pre-requisites
1)Drag & drop the “Fileupload” control (“FileUpload1”)into an aspx page(“latest15.aspx” ).You will get “Fileupload” control from visualstudio.Net standard toolbar.
2)Add a button to the page( “Button_Upload”) .
The fileupload control itself helps browsing our system,I am not going on explaining just check out the code below.It is the code file of the page.
“latest15.aspx.cs”
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;public partial class latest15 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Upload_Click(object sender, EventArgs e)
{
FileUpload1.SaveAs(Server.MapPath(Request.ApplicationPath)+”\\”+FileUpload1.FileName);
}
}
Notes:
1) “Savesas” is used to save the file,and the parameter for this method is the location where we need to save the file.
2) “Server.MapPath(Request.ApplicationPath)” will give our project location,where all our files are kept.This will be normal inside the visualstudio folder->websites .
3) “FileUpload1.FileName” will get the name of the selected file.
You might be surprised at first that no new file came in your solution explorer,But my code works for sure,right click on the projectname press “Refresh Folder”.The uploaded file will be there.
Hope this thing helps,don’t hesitate to ask any doubts.
Related posts:








Leave your response!