if (fileupload.PostedFile != null)
{
//addto为要添加的属性,aboutfile为文件说明
string nam = fileupload.PostedFile.FileName;
//取得文件名(抱括路径)里最后一个"."的索引
int i = nam.LastIndexOf(".");
//取得文件扩展名
string newext = nam.Substring(i);
//这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
DateTime now = DateTime.Now;
string newname = now.DayOfYear.ToString() + fileupload.PostedFile.ContentLength.ToString();
fileupload.PostedFile.SaveAs(Server.MapPath("upload//" + newname + newext));
//下面是生成缩略图
System.Drawing.Image image,aNewImage;
int width,height,newwidth,newheight;
image = System.Drawing.Image.FromFile(Server.MapPath("upload//" + newname + newext));
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
width = image.Width;
height = image.Height;
newwidth=171;
newheight=111;
newheight=height*newwidth/width;
aNewImage = image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr());
aNewImage.Save(Server.MapPath("upload//small_" + newname + newext));
}