Create File Uploader (Visual Studio)

By this Coding you can create File Uploader 
and the is file will uploaded into Foder:- 
 
 Design Source Code:- 
 
<form id="form1" runat="server">
    <asp:FileUpload id="FileUploadControl" runat="server" />
    <asp:Button runat="server" id="UploadButton" text="Upload" 
     onclick="UploadButton_Click" />
    <br /><br />
    <asp:Label runat="server" id="StatusLabel" text="Upload 
     status: " />
</form>
Coding C#:
protected void UploadButton_Click(object sender, EventArgs e)
{
if(FileUploadControl.HasFile)
{
try
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/Folderpath") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch(Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded.
The following error occured: " + ex.Message;
}
}
}

Comments

Post a Comment

Popular posts from this blog

The Page Life Cycle of an ASP.NET and its controls.

Embed Tiny Editor in Your Web Application:

Delete data from Gridview using Command Field