CopyCode The Code is as follows: protected void button#click (Object sender, eventargs E)
{
String filename = This. dropdownlist1.selectedvalue; // The final name
If (this. fileupload1.postedfile! = NULL)
{
String basefilename = This. fileupload1.postedfile. filename; // get the uploaded file name
Int I = basefilename. lastindexof (".");
String ext = basefilename. substring (I); // get the file extension
String savepath = server. mappath ("~ /PIC /");
If (! System. Io. Directory. exists (savepath ))
{
System. Io. Directory. createdirectory (savepath );
}
Savepath = savepath + "\" + filename + ext;
// Response. Write (EXT );
If (! Ext. Equals (". jpg ")&&! Ext. Equals (". jpeg ")&&! Ext. Equals (". BMP ")&&! Ext. Equals (". GIF ")&&! Ext. Equals (". PNG "))
{
Response. Write ("the format of the uploaded file is incorrect! <A href = "\" href = "\" "Upload. aspx \"> re-upload </a> ");
Response. End ();
}
Fileupload1.postedfile. saveas (savepath );
}
}
It includes extension verification and file rename.