Pooja Chowdhury

Pooja Chowdhury

  • NA
  • 396
  • 39.5k

multiple images upload

Aug 30 2017 4:00 AM
i already wrote the code images were also uploaded but when i see these in a folder all the images are same with different name
 
protected void button1_Click(object sender, EventArgs e)
{
label1.Text = "<b>uploaded file<b/><br/>";
labbel2.Text = "<b>not uploaded file<b/><br/>";
label1.Visible = true;
try
{
// Check File Prasent or not
if (fileuplaod1.HasFiles)
{
int filecount = 0;
int fileuploadcount = 0;
//check No of Files Selected
filecount = fileuplaod1.PostedFiles.Count();
if (filecount <= 10)
{
foreach (HttpPostedFile postfiles in fileuplaod1.PostedFiles)
{
//Get The File Extension
string filetype = Path.GetExtension(postfiles.FileName);
if (filetype.ToLower() == ".docx" || filetype.ToLower() == ".pdf" || filetype.ToLower() == ".txt" || filetype.ToLower() == ".doc" || filetype.ToLower() == ".png" || filetype.ToLower() == ".jpg")
{
//Get The File Size In Bite
double filesize = postfiles.ContentLength;
if (filesize < (1048576))
{
fileuploadcount++;
string serverfolder = string.Empty;
string serverpath = string.Empty;
// Adding File Into Scecific Folder Depend On his Extension
switch (filetype)
{
case ".doc":
case ".docx":
serverfolder = Server.MapPath(@"uplaodfiles\document\");
//check Folder avlalible or not
if (!Directory.Exists(serverfolder))
{
// create Folder
Directory.CreateDirectory(serverfolder);
}
serverpath = serverfolder + Path.GetFileName(postfiles.FileName);
fileuplaod1.SaveAs(serverpath);
label1.Text += "[" + postfiles.FileName + "]- document file uploaded successfully<br/>";
break;
case ".pdf":
serverfolder = Server.MapPath(@"uplaodfiles\pdf\");
//check Folder avlalible or not
if (!Directory.Exists(serverfolder))
{
// create Folder
Directory.CreateDirectory(serverfolder);
}
serverpath = serverfolder + Path.GetFileName(postfiles.FileName);
fileuplaod1.SaveAs(serverpath);
label1.Text += "[" + postfiles.FileName + "]- pdf file uploaded successfully<br/>";
break;
case ".png":
serverfolder = Server.MapPath(@"uplaodfiles\");
//check Folder avlalible or not
if (!Directory.Exists(serverfolder))
{
// create Folder
Directory.CreateDirectory(serverfolder);
}
serverpath = serverfolder + Path.GetFileName(postfiles.FileName);
fileuplaod1.SaveAs(serverpath);
label1.Text += "[" + postfiles.FileName + "]- png file uploaded successfully<br/>";
break;
case ".jpg":
serverfolder = Server.MapPath(@"uplaodfiles\");
//check Folder avlalible or not
if (!Directory.Exists(serverfolder))
{
// create Folder
Directory.CreateDirectory(serverfolder);
}
serverpath = serverfolder + Path.GetFileName(postfiles.FileName);
fileuplaod1.SaveAs(serverpath);
label1.Text += "[" + postfiles.FileName + "]- jpg file uploaded successfully<br/>";
break;

case ".txt":
serverfolder = Server.MapPath(@"uplaodfiles\text_document\");
//check Folder avlalible or not
if (!Directory.Exists(serverfolder))
{
// create Folder
Directory.CreateDirectory(serverfolder);
}
serverpath = serverfolder + Path.GetFileName(postfiles.FileName);
fileuplaod1.SaveAs(serverpath);
label1.Text += "[" + postfiles.FileName + "]- text_document file uploaded successfully <br/>";
break;
}
}
else
{
labbel2.Text += "[" + postfiles.FileName + "]- files not uploded size is greater then(1)MB.<br/>Your File Size is(" + (filesize / (1024 * 1034)) + ") MB </br>";
}
}
else
{
labbel2.Text += "[" + postfiles.FileName + "]- file type must be .doc or pdf and other<br/>";
}
}
}
else
{
label1.Visible = false;
labbel2.Text = "you are select(" + filecount + ")files <br/>";
labbel2.Text += "please select Maximum five(10) files !!!";
}
label3.Visible = true;
label3.Text = "ToTal File =(" + filecount + ")<br/> Uploded file =(" + fileuploadcount + ")<br/> Not Uploaded=(" + (filecount - fileuploadcount) + ")";
}
else
{
label1.Visible = false;
label3.Visible = false;
labbel2.Text = "<b>please select the file for upload !!!</b></br>";
}
}
catch (Exception ex)
{
labbel2.Text = ex.Message;
}


Answers (1)