Вы находитесь на странице: 1из 6

FILE UPLOAD APPLICATION ASP.

NET C#
Hello Friends hope all doing well today I am share my article FILE
UPLOAD APPLICATION ASP.NET C# so I hope helpful for you.

Step 1:- need to have installed VS in your machine (laptop & desktop)
open Visual Studio start new project.

Step 2:- select web and select asp.net web application empty look like
below enter your application name and click OK.
Step 3:- click solution explore right click add new item add OK. Then
design page like drag and drop upload file one button one label

Design page below


Below source codes of design page

<%@ Page Language="C#" AutoEventWireup="true"


CodeBehind="WebForm1.aspx.cs"
Inherits="FileUploadapplication.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

</div>
<asp:FileUpload ID="FileUpload1" runat="server"
BackColor="#FF66CC" Font-Size="Medium" Height="38px"
Width="301px" />
<p>
<asp:Button ID="Button1" runat="server"
BackColor="Aqua" BorderStyle="Solid" Font-Bold="True" Font-
Italic="False" Font-Size="X-Large" Height="48px"
OnClick="Button1_Click" Text="Upload" Width="226px" />
<asp:Label ID="Label1" runat="server"
BackColor="Lime" Font-Size="Medium"
Text="Label"></asp:Label>
</p>
</form>
</body>
</html>

After that click upload button writes below codes.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FileUploadapplication
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender,


EventArgs e)
{
if (FileUpload1.HasFile) //fileupload control
contains a file
try
{
FileUpload1.SaveAs("E:\\" +
FileUpload1.FileName); // file path where you want
to upload
Label1.Text = "File Uploaded Sucessfully
!! " + FileUpload1.PostedFile.ContentLength + "mb"; //
get the size of the uploaded file
}
catch (Exception ex)
{
Label1.Text = "File Not Uploaded!!" +
ex.Message.ToString();
}
else
{
Label1.Text = "Please Select File and Upload
Again";

}
}
}
}

Output of program
When I have click choose file open file like below select file and click
upload

Keep reading share your feedback …..keep writing…..Thanks

Вам также может понравиться