Results 1 to 2 of 2

Thread: How to use Upload control in ASP.NET

  1. #1
    Garcíarobine is offline Senior Member
    Join Date
    Dec 2009
    Posts
    334
    Rep Power
    3

    Default How to use Upload control in ASP.NET

    Hi. I am learning asp.net programming language. Currently I try to understand each an every control but I am little bit confuse in upload control. I tried to search it on internet but I am not getting any solution and need some help for solving that problem.

  2. #2
    RodríguezBrown is offline Senior Member
    Join Date
    Dec 2009
    Posts
    322
    Rep Power
    3

    Default

    With ASP.NET, accepting file uploads from users has very easy. With the FileUpload control, it is possible with a small amount of code lines, check the following example.

    Code:
    <form id="form1" runat="server">
        <asp:FileUpload id="FileUploadControl" runat="server" />
        <asp:Button runat="server" id="btn_Upload" text="Upload" onclick="UploadButton_Click" />
        <br /><br />
        <asp:Label runat="server" id="lbl_Status" text="Upload status: " />
    </form>
    And here is the CodeBehind code required to handle the upload:

    Code:
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        if(FileUploadControl.HasFile)
        {
            try
            {
                string filename = Path.GetFileName(FileUploadControl.FileName);
                FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
                lbl_Status.Text = “File uploaded successfully!";
            }
            catch(Exception ex)
            {
                lbl_Status.Text = “The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    }

Similar Threads

  1. How to upload file in asp.net
    By ThomasBarnes in forum Programming
    Replies: 1
    Last Post: 02-09-2010, 04:23 PM
  2. How to Upload a Website to an FTP Address
    By CarterBaker in forum Networking Jargons
    Replies: 0
    Last Post: 12-28-2009, 07:34 PM
  3. Upload
    By gorden in forum Everything Else
    Replies: 0
    Last Post: 04-03-2009, 10:35 AM
  4. Want to Upload the Video
    By allster in forum General Internet Terms
    Replies: 1
    Last Post: 02-11-2009, 07:24 AM
  5. Upload music to your profile
    By winstore in forum General Internet Terms
    Replies: 0
    Last Post: 07-14-2008, 06:32 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48