Results 1 to 2 of 2

Thread: How to upload file in asp.net

  1. #1
    ThomasBarnes is offline Senior Member
    Join Date
    Dec 2009
    Posts
    303
    Rep Power
    3

    Default How to upload file in asp.net

    I am learning asp.net programming language. I am working on one live project. In this project I want to upload file using upload control. I tried different method but any of them worked out. Can anybody tell me how to upload file in asp.net?

  2. #2
    HernandezOrtiz is offline Senior Member
    Join Date
    Dec 2009
    Posts
    301
    Rep Power
    3

    Default

    Just take the FileUpload control from Toolbox to a Web page. The following code adds the FileUpLoad control:

    Code:
    <asp:FileUpLoad id="FileUpLoad1" runat="server" />
    To support file upload, we need to add a Button control: 
    <asp:Button id="btn_upload" Text="Upload File" OnClick="btn_upload_Click" runat="server" Width="105px" />
    In button click event handler, we would like to call SaveAs method of FileUpLoad control, which gets an entire path where the file will be uploaded.

    Code:
    protected void btn_upload_Click(object sender, EventArgs e)
    {
    if (FileUpLoad1.HasFile)
    {
    FileUpLoad1.SaveAs(@"C:temp" + FileUpLoad1.FileName);
    Label1.Text = "File Uploaded: " + FileUpLoad1.FileName ;
    }
    else
    {
    Label1.Text = "No File Uploaded.";
    }
    }
    The page looks like Figure 1.

    Fig ure 1. FileUpLoad control:

Similar Threads

  1. Code for file upload in VB.net
    By BakerJones in forum Programming
    Replies: 2
    Last Post: 06-17-2010, 01:53 PM
  2. How to use Upload control in ASP.NET
    By Garcíarobine in forum Software Jargons
    Replies: 1
    Last Post: 04-20-2010, 01:18 PM
  3. How Do I Upload Movies onto My Computer?
    By CarterBaker in forum Software Jargons
    Replies: 0
    Last Post: 01-02-2010, 03:40 PM
  4. Upload
    By gorden in forum Everything Else
    Replies: 0
    Last Post: 04-03-2009, 10:35 AM
  5. Want to Upload the Video
    By allster in forum General Internet Terms
    Replies: 1
    Last Post: 02-11-2009, 07:24 AM

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