>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
图片上传到服务器
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile.ContentLength < 800000)//100000为100K
{
string fileFullname = this.FileUpload1.FileName;
string dataName = DateTime.Now.ToString("yyyyMMddhhmmss");
string fileName = fileFullname.Substring(fileFullname.LastIndexOf("\\") + 1);
string type = fileFullname.Substring(fileFullname.LastIndexOf(".") + 1);
if (type == "bmp" || type == "jpg" || type == "png" || type == "JPG" || type == "BMP" || type == "PNG" || type == "jpeg" || type == "JPEG")
{
this.FileUpload1.SaveAs(Server.MapPath("~/upload") + "\\" + dataName + "." + type);
string ProImg = "upload/" + dataName + "." + type;
this.TextBox1.Text = "upload/" + dataName + "." + type; // 存储路径
}
else { Response.Write("<script language='javascript'>alert('图片上传失败,请选择格式为:jpg,jpeg,png,bmp的图片!');</script>"); }
}
else
{ Response.Write("<script language='javascript'>alert('请上传小于800K的图片!');</script>"); }
}
>>>>>>>>>>>>>>>>>>>>>>>前台加一个fileupload和一个button即可