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 take the relative directory of the current file. In asp.net "/" must use "//" instead, "upload//" to "//upload//" to take the current file absolute directory
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 ();