First, put an html input (File) control on the page to name it myFile, and then run it as a server disconnection control.
Put another Button and add the following code in the Button click event:
If (this. myFile. PostedFile! = Null)
{
String photoName1 = myFile. PostedFile. FileName; // get the initial file name
Int I = photoName1.LastIndexOf ("."); // retrieve the index of the last "." In the file name
String newext = photoName1.Substring (I); // get the file extension
If (! FileEXT (newext ))
{
Response. Write ("the file format is incorrect! ");
Response. End ();
}
DateTime now = DateTime. Now; // obtain the system time
PhotoName2 = now. ToString ("yyyyMMddhhmmss") + newext; // rename the file to obtain the year, month, day, hour, minute, and second of the time.
MyFile. PostedFile. SaveAs (Server. MapPath ("Upload/" + photoName2 ));
// Save the file to the path and use Server. MapPath () to obtain the absolute directory of the current file
}