//Check that the uploaded file is not empty
if(File1.PostedFile!=null)
{
string nam = File1.PostedFile.FileName;
//Get the index of the last "." in the file name (enclosed path)
int i= nam.LastIndexOf(".");
//Get file extension
string newext =nam.Substring(i);
//Here I automatically name the files based on the date and file size to ensure that the file names are 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: I use Server.MapPath() here to get the absolute directory of the current file. In asp.net, "" must be replaced with ""
File1.PostedFile.SaveAs(Server.MapPath("upload"+newname+newext));
this.HyperLink1.NavigateUrl = "upload"+newname+newext;
//Get the relevant attributes of this file: file name, file type, file size
//fname.Text=File1.PostedFile.FileName;
//fenc.Text=File1.PostedFile.ContentType;
//fsize.Text=File1.PostedFile.ContentLength.ToString();
}