Click the button to upload the fileupload image.
Protected void button3_click (Object sender, imageclickeventargs E)
{
If (fileupload1.hasfile)
{
// Rename the image
String strfilename1 = fileupload1.filename; // obtain the name of the uploaded file.
String [] myfile = strfilename1.split ('.'); // separate the file name from the file type.
String dotname = myfile [myfile. Length-1]. tostring (). tolower (); // obtain the file type
If (dotname = "GIF" | dotname = "jpg ")
{
String filepath = path. getfullpath (fileupload1.postedfile. filename );
Random myrdn = new random (); // generate a random number
Strfilename1 = datetime. Now. tostring ("yymmddhhmm") + myrdn. Next (10000). tostring () + "." + dotname;
String imgpath = server. mappath ("userimg /");
String folder = "BB"; // name of the created folder
If (! System. Io. Directory. exists (imgpath + folder ))
{
// Automatically generate a folder
System. Io. Directory. createdirectory (imgpath + folder );
}
Fileupload1.saveas (imgpath + folder + "//" + strfilename1 );
Page. clientscript. registerstartupscript (this. GetType (), "", "<SCRIPT> alert ('uploaded successfully'); </SCRIPT> ");
}
Else
{
Page. clientscript. registerstartupscript (this. GetType (), "", "<SCRIPT> alert ('wrong image type! ') </SCRIPT> ");
}
}
}