Wednesday 12 February 2014

Example Upload File - ASP.NET

Leave a Comment
This is example of upload file using asp.net.

Html 

 <fieldset style="width: 804px" align="center">
        <legend><em>Using the FileUpload Control</em>&nbsp;</legend>
        <div align="left" style="text-align: center">
            <form id="form1" runat="server">
                <div>
                    <table style="width: 90%">
                        <tr>
                            <td colspan="2">
                                <br />
                                <asp:Label ID="LSuccessMssg" runat="server"></asp:Label>
                                <asp:FileUpload ID="FileUpload1" runat="server" /><asp:Button ID="buttonUpload" runat="server"
                                    Text="Upload" OnClick="buttonUpload_Click1" /></td>
                        </tr>
                    </table>
                </div>
            </form>
        </div>
    </fieldset> 

Code Behind

 protected void UploadThisFile(FileUpload upload)
    {
        if (upload.HasFile)
        {
            string theFileName = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName);
            if (File.Exists(theFileName))
            {
                File.Delete(theFileName);
            }
            upload.SaveAs(theFileName);
        }
    }   

    protected void buttonUpload_Click1(object sender, EventArgs e)
    {
        UploadThisFile(FileUpload1);
        LSuccessMssg.Text = "Successfully upload File";
    }


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.