Click here to Skip to main content
15,922,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone
I am trying to upload some files attached to a list box into my computer but I get an error that says you cannot open a closed file(s)
Below is my code:
C#
protected void btnUpload_Click(object sender, EventArgs e)
{
  int sessionCount = Session.Count;

  for (int i = sessionCount - 1; i >= 0; i--)
  {
    if (sessionCount <= 3)
    {
      HtmlInputFile hif = (HtmlInputFile)Session["myupload" + i];

      if (hif.PostedFile.ContentLength <= 500000)
      {
        string storePath = Server.MapPath("~") + "/MultipleUpload";

        if (!Directory.Exists(storePath))

          Directory.CreateDirectory(storePath);
        hif.PostedFile.SaveAs(storePath + "/" + Path.GetFileName
          (hif.PostedFile.FileName));
        lblError.Text = "Your Files are uploaded successfully";
        ListBox1.Items.Clear();
      }
      else
          lblError.Text = "An error occured";
    }
    else
        lblError.Text =
        "You have exceeded the maximum number of files to be uploaded (3)";

  }
  Session.RemoveAll();
}
I dont know what I am doing wrong please I need help

Thanks in advance
Posted
Updated 8-Feb-14 20:24pm
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900