TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Pooja Chowdhury
NA
396
39.1k
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;
}
}
Reply
Answers (
1
)
putting data with A+ctri key.
MVC Database first Aproach issue