File Upload control in asp.net

 Example: Write a program to demonstrate the use of file upload control. 

.aspx file Code: 

<html >

<head runat="server">

    <title>Aryan Computers(File Upload) </title>

</head>

<body>

    <form id="form1" runat="server">

    <div style="margin-left: 40px">

    

        <asp:Label ID="Label1" runat="server" Font-Bold="True" 

            Font-Names="Bookman Old Style" ForeColor="#CC0099" 

            Text="Example of File Upload" Font-Size="X-Large" Font-Strikeout="False" 

            Font-Underline="True"></asp:Label>

   <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="XX-Large" 

            ForeColor="#00CC00"></asp:Label>

        </div>

    <asp:FileUpload ID="FileUpload1" runat="server" style="margin-top: 0px" />

    <br />

    <div style="margin-left: 120px">

        <asp:Button ID="Button1" runat="server" Font-Bold="True" 

            onclick="Button1_Click" Text="Upload" Width="125px" />

    </div>

    </form>

</body>

</html>

.aspx.cs file Code: 

public partial class WebForm6 : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {        }

        protected void Button1_Click(object sender, EventArgs e)

        {

            if (FileUpload1.HasFile)

            {

                FileUpload1.SaveAs(@"C:\Save_file\" + FileUpload1.FileName);

                Label2.Text = " Upload File is  :" + FileUpload1.FileName;

            }

            else

            {

             Label2.Text = " File is not Uploaded ??   Plz Select a File .....";

            }

        }

    }

Output: 



Comments

Popular posts from this blog

simple program C#

Regular Expression Validator Control in asp.net

two dimension array in C#