} ProtectedVoidButton#click (ObjectSender, eventargs E) { StringUploadfilename, uploadfilelastname;
Uploadfilename=Fileupload1.postedfile. filename;//Original Local Location of the file Uploadfilelastname=Uploadfilename. substring (uploadfilename. lastindexof (".")+1);//Get the file extension Random Rd=NewRandom ();//Generate random number IntValationno=10+Rd. Next (99);//Generate random number StringSuiji=Valationno. tostring ();//Generate random number StringUploadfiletime=Datetime. Now. tostring ("Yyyymmddhhmmss")+Suiji;//Obtain the system time and add a random number to generate the name of the uploaded image. StringNewuploadfilename=Uploadfiletime+"."+Uploadfilelastname;//Name of the uploaded Image StringUserdirectory="Testfile";//The name of the folder to be created. You can register an ID in actual use. StringUserpath=Server. mappath ("Uploadfiles"). Tostring ()+"\\"+Userdirectory+"\\"+"Productsimages"; If(!Directory. exists (userpath ))//Create a folder if the folder does not exist. {
Directory. createdirectory (userpath );
}
Fileupload1.postedfile. saveas (newuploadpahtname );//Upload the image as saved StringSuser_productsimageurl="Uploadfiles/"+Userdirectory+"/"+"Productsimages/"+Newuploadfilename;//Obtain the virtual path of the server Image //Response. Write (suser_productsimageurl ); }
}
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