asp.net| Upload | download
Check that the upload file is not empty
if (file1.postedfile!=null)
{
String nam = File1.PostedFile.FileName;
Gets the last "." in the filename (enclosing path). The index
int i= Nam. LastIndexOf (".");
Get file name extension
String Newext =nam. Substring (i);
Here I automatically name the file according to the date and file size to ensure that the filename is not duplicated
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.
Note: I use Server.MapPath () to take the absolute directory of the current file. In the asp.net, "" must be replaced by "".
File1.PostedFile.SaveAs (Server.MapPath ("Upload" +newname+newext));
This. Hyperlink1.navigateurl = "Upload" +newname+newext;
Get the related 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 ();
}