Thumbnail if (fileupload. Postedfile!=null)
{
AddTo for the property to be added, Aboutfile for the file description
String nam = FileUpload. 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 () +fileupload. 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 get the relative directory of the current file. In asp.net "\" must be replaced by "\", the "upload\\" to "\\upload\\" has become the absolute directory of the current file
FileUpload. Postedfile.saveas (Server.MapPath ("upload\\" +newname+newext));
Get the related attributes of this file: file name, file type, file size
FName. Text=myfile.postedfile.filename;
Fenc. Text=myfile.postedfile.contenttype;
Fsize. Text=myfile.postedfile.contentlength.tostring ();
Here is the build thumbnail
System.Drawing.Image Image,anewimage;
int width,height,newwidth,newheight;
Image=system.drawing.image.fromfile (Server.MapPath) ("upload/" +newname. ToString () +newext. ToString ()));
System.Drawing.Image.GetThumbnailImageAbort callb =new System.Drawing.Image.GetThumbnailImageAbort ( Thumbnailcallback);
Width=image. Width;
Height=image. Height;
if (firstpageshow. selectedvalue.tostring () = = "1" &&fenlei. selectedvalue.tostring () = = "5")
{
newwidth=203;newheight=86;
Newheight=height*newwidth/width;
}
else if (Isweekman. selectedvalue.tostring () = = "1")
{
newwidth=171;newheight=111;
Newheight=height*newwidth/width;
}
else if (firstpageshow. selectedvalue.tostring () = = "1" &&fenlei. selectedvalue.tostring () = = "3")
{
newwidth=171;newheight=111;
Newheight=height*newwidth/width;
}
Else
{
newwidth=62;newheight=80;
Newheight=height*newwidth/width;
}
Anewimage=image. Getthumbnailimage (Newwidth,newheight,callb,new system.intptr ());
Anewimage.save (Server.MapPath ("upload\\" + "Small_" +newname+newext));
Image. Dispose ();
Build and save the thumbnail, save name is added a Small_ before the original name.
Pic= "upload/" +newname. ToString () +newext. ToString ();
Smallpic= "Upload/small_" +newname. ToString () +newext. 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