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 ();
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service