string name = this.FileUpload1.FileName;//文件名字
string size = this.FileUpload1.PostedFile.ContentLength.ToString();//文件大小
string type = this.FileUpload1.PostedFile.ContentType;//文件类型ype == "image/pjpeg" || type == "image/gif" || type == "x-png"
string type2 = name.Substring(name.LastIndexOf(".") + 1);//文件类型
string path = Server.MapPath("~/fileload/") + "//" + DateTime.Now.ToString("yyyyMMddhhmmssffff") + "." + type2; ;//实际路径
string datapath = "fileload/" + DateTime.Now.ToString("yyyyMMddhhmmssffff") +"."+ type2;
if (Convert.ToInt32(size) > 2048)
{
this.Label1.Text = "上传失败文件大于2m";
}
if (type == "image/gif" || type == "image/bmp" || type == "image/pjpeg" || type == "image/x-png")
{
this.FileUpload1.SaveAs(path);
this.Label1.Text = "上传成功";
this.fileimages.Text = datapath;
}
else
{
this.Label1.Text = "文件类型不对上传失败";
}
上传的类型什么的自己改下吧。 都有注释,不会的话你在问我吧