Copy Code code as follows:
protected void Button1_Click (object sender, EventArgs e)
{
string filename = this. dropdownlist1.selectedvalue;//Final Name
if (this. Fileupload1.postedfile!= null)
{
String basefilename = this. fileupload1.postedfile.filename;//Get upload file filename
int i = Basefilename.lastindexof (".");
String ext = basefilename.substring (i);//Get 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 ("Upload file format is not correct!") <a href= "\" href= "\" "Upload.aspx\ > re-upload </a>");
Response.End ();
}
FileUpload1.PostedFile.SaveAs (Savepath);
}
}
Built-in extension verification and file rename features