Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. I wanted to upload Multiple Files With ListBox in ASP.NET

I wanted to upload Multiple Files With ListBox in ASP.NET

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasesysadminhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 12016106
    wrote on last edited by
    #1

    I wanted to upload Multiple Files With ListBox in ASP.NET but there is an error at specific place.... The error on :

    File.Add(FileUpload1);

    It showing error on 'File.Add' asp:

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" style="z-index: 1; left: 420px; top: 315px; position: absolute; width: 285px; height: 22px" />
    <asp:Button ID="btnUpload" Text="Add" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg, application/exe" style="z-index: 1; left: 425px; top: 535px; position: absolute" />
    <hr />
    <asp:Label ID="lbl_text" runat="server" ForeColor ="Red" style="z-index: 1; left: 701px; top: 495px; position: absolute" />
    <asp:ListBox ID="ListBox1" runat="server" style="z-index: 1; left: 415px; top: 371px; position: absolute; width: 280px; height: 147px; margin-left: 3px; margin-top: 0px"></asp:ListBox>
    <asp:Button ID="btn_remove" runat="server" OnClick="btn_remove_Click" style="z-index: 1; left: 500px; top: 535px; position: absolute" Text="Remove" />

    c#:

    ///<link to upload button>
    protected void UploadMultipleFiles(object sender, EventArgs e)
    {
    try
    {
    if (FileUpload1.HasFile)
    {
    if (FileUpload1.PostedFile.ContentLength > 0)
    {
    if (ListBox1.Items.Contains(new ListItem(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName))))
    {
    lbl_text.Text = "File already in the ListBox";
    }
    else
    {
    File.Add(FileUpload1);
    ListBox1.Items.Add(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName));
    lbl_text.Text = "Add another file or click Upload to save them all";
    }
    }
    else
    {
    lbl_text.Text = "Fi

    A 1 Reply Last reply
    0
    • M Member 12016106

      I wanted to upload Multiple Files With ListBox in ASP.NET but there is an error at specific place.... The error on :

      File.Add(FileUpload1);

      It showing error on 'File.Add' asp:

      <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
      <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" style="z-index: 1; left: 420px; top: 315px; position: absolute; width: 285px; height: 22px" />
      <asp:Button ID="btnUpload" Text="Add" runat="server" OnClick ="UploadMultipleFiles" accept ="image/gif, image/jpeg, application/exe" style="z-index: 1; left: 425px; top: 535px; position: absolute" />
      <hr />
      <asp:Label ID="lbl_text" runat="server" ForeColor ="Red" style="z-index: 1; left: 701px; top: 495px; position: absolute" />
      <asp:ListBox ID="ListBox1" runat="server" style="z-index: 1; left: 415px; top: 371px; position: absolute; width: 280px; height: 147px; margin-left: 3px; margin-top: 0px"></asp:ListBox>
      <asp:Button ID="btn_remove" runat="server" OnClick="btn_remove_Click" style="z-index: 1; left: 500px; top: 535px; position: absolute" Text="Remove" />

      c#:

      ///<link to upload button>
      protected void UploadMultipleFiles(object sender, EventArgs e)
      {
      try
      {
      if (FileUpload1.HasFile)
      {
      if (FileUpload1.PostedFile.ContentLength > 0)
      {
      if (ListBox1.Items.Contains(new ListItem(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName))))
      {
      lbl_text.Text = "File already in the ListBox";
      }
      else
      {
      File.Add(FileUpload1);
      ListBox1.Items.Add(System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName));
      lbl_text.Text = "Add another file or click Upload to save them all";
      }
      }
      else
      {
      lbl_text.Text = "Fi

      A Offline
      A Offline
      aarif moh shaikh
      wrote on last edited by
      #2

      What error you got??

      M 2 Replies Last reply
      0
      • A aarif moh shaikh

        What error you got??

        M Offline
        M Offline
        Member 12016106
        wrote on last edited by
        #3

        The name 'Files' does not exist in the current context

        1 Reply Last reply
        0
        • A aarif moh shaikh

          What error you got??

          M Offline
          M Offline
          Member 12016106
          wrote on last edited by
          #4

          Thank you so much for your help. I got the answer. I did not declare file, that's why it shows error. now I'm done.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups