// Check that the uploaded file is not empty
If (file1.postedfile! = NULL)
{
String Nam = file1.postedfile. filename;
// Obtain the index of the last "." In the file name (including the path)
Int I = Nam. lastindexof (".");
// Get the file extension
String newext = Nam. substring (I );
// Here, I automatically name the File Based on the date and file size to ensure that the file name is not repeated
Datetime now = datetime. now;
String newname = now. dayofyear. tostring () + file1.postedfile. contentlength. tostring ();
// Save the file to the directory you want. This is the upload directory under the IIS root directory. You can change it.
// Note: Here I use server. mappath () to retrieve the absolute directory of the current file. In Asp.net, "" must be replaced ""
File1.postedfile. saveas (server. mappath ("Upload" + newname + newext ));
This. hyperlink1.navigateurl = "Upload" + newname + newext;
// Obtain the relevant attributes of the file: file name, file type, and file size.
// Fname. Text = file1.postedfile. filename;
// Fenc. Text = file1.postedfile. contenttype;
// Fsize. Text = file1.postedfile. contentlength. tostring ();
}