Vikas Ahlawat

Vikas Ahlawat

  • NA
  • 564
  • 817.7k

Multiple file upload problem

Jul 13 2011 2:35 AM
Hi
I am using 5 fileupload control in my page.
now on button click I want to upload images with its thumbnails.
but when i resize the image then it gives error.
because its

 protected void uploadimageButton_Click(object sender, EventArgs e)
  {
  string selectedcategory = categorynameDropDownList.SelectedItem.Text;
 
 
  // string imagename = ablumcoverFileUpload.PostedFile.FileName;
  // string path = Server.MapPath("Albums/" + selectedcategory  + "/");
  // string imagepath = path + filename;
  try
  {

  //To Upload Multiple Files on Single Click

  HttpFileCollection albumimages = Request.Files;
  int count= albumimages.Count//everytime it give 5
  string[] imagename = new string[count];
  string[] thumnailimagename=new string[count];

  for (int i = 0; i <count-1 ; i++)
  {
 
  HttpPostedFile albumimagefile = albumimages[i];

  ThumnailImages(selectedcategory, albumimages[i]); //convert image to thumnail
 
  }
 
  }

  catch (Exception ex)
  {
  msg.Text = ex.Message;
  }

  }



 public void ThumnailImages(string categoryname, HttpPostedFile myimage)
  {

....
......
  Graphics oGraphics = null;
  Bitmap originalBMP = new Bitmap(myimage.InputStream); // Error occur here because when i select only two images for uploading , but the loop run 5 times then , on the third calling there is null parameter


So the main problem is that how to know that how many fileupload control have files




Answers (3)