if (UpLoad())
{
//得到上传文件的全路径
string fullName = this.FileUpload1.PostedFile.FileName;
//HiddenField1.Value = this.FileUpload1.PostedFile.FileName;
//截取文件路径"\"后的字符(包括"\",所有索引值要加1)
string fileName = fullName.Substring(fullName.LastIndexOf("\\") + 1);
//截取文件路径"."后的字符(包括".",所有索引值要加1)
string type = fullName.Substring(fullName.LastIndexOf(".") + 1).ToLower();
minf.PhotoLJ = HiddenField1.Value;
}
return minf;--返回一个实体对象
} private bool UpLoad()
{
//string folderNews = string.Format("F:/Web/zxyAdmin/Exhibit/chenou");
string folderNews = Server.MapPath("Photo\\");
if (!System.IO.Directory.Exists(folderNews))
{
System.IO.Directory.CreateDirectory(folderNews);
}//得到上传文件的全路径
string fullName = this.FileUpload1.PostedFile.FileName;
if (string.IsNullOrEmpty(fullName)) return true;
//截取文件路径"\"后的字符(包括"\",所有索引值要加1)
string fileName = fullName.Substring(fullName.LastIndexOf("\\") + 1);
//截取文件路径"."后的字符(包括".",所有索引值要加1)
string type = fullName.Substring(fullName.LastIndexOf(".") + 1).ToLower();
//if (type == "bmp" || type == "jpg" || type == "gif")
if (type == "jpg" || type == "bmp" || type == "gif")
{
if (FileUpload1.PostedFile.ContentLength > 1024 * 1024)
{
Page.ClientScript.RegisterStartupScript(GetType(), "big", "<script language='javascript'>alert('你上传的图片不能超过1M!')</script>");
return false;
}
this.FileUpload1.SaveAs(Server.MapPath("Photo\\") + UpLoadPhotoName + "." + type);
HiddenField1.Value = "/zxyAdmin/Exhibit/Photo/" + UpLoadPhotoName + "." + type;
return true;
}
else
{ //不是合法格式做的处理
Page.ClientScript.RegisterStartupScript(GetType(), "scsp", "<script language='javascript'>alert('你图片上传的格式不正确!')</script>");
return false;
}
//} }
{
//得到上传文件的全路径
string fullName = this.FileUpload1.PostedFile.FileName;
//HiddenField1.Value = this.FileUpload1.PostedFile.FileName;
//截取文件路径"\"后的字符(包括"\",所有索引值要加1)
string fileName = fullName.Substring(fullName.LastIndexOf("\\") + 1);
//截取文件路径"."后的字符(包括".",所有索引值要加1)
string type = fullName.Substring(fullName.LastIndexOf(".") + 1).ToLower();
minf.PhotoLJ = HiddenField1.Value;
}
return minf;--返回一个实体对象
} private bool UpLoad()
{
//string folderNews = string.Format("F:/Web/zxyAdmin/Exhibit/chenou");
string folderNews = Server.MapPath("Photo\\");
if (!System.IO.Directory.Exists(folderNews))
{
System.IO.Directory.CreateDirectory(folderNews);
}//得到上传文件的全路径
string fullName = this.FileUpload1.PostedFile.FileName;
if (string.IsNullOrEmpty(fullName)) return true;
//截取文件路径"\"后的字符(包括"\",所有索引值要加1)
string fileName = fullName.Substring(fullName.LastIndexOf("\\") + 1);
//截取文件路径"."后的字符(包括".",所有索引值要加1)
string type = fullName.Substring(fullName.LastIndexOf(".") + 1).ToLower();
//if (type == "bmp" || type == "jpg" || type == "gif")
if (type == "jpg" || type == "bmp" || type == "gif")
{
if (FileUpload1.PostedFile.ContentLength > 1024 * 1024)
{
Page.ClientScript.RegisterStartupScript(GetType(), "big", "<script language='javascript'>alert('你上传的图片不能超过1M!')</script>");
return false;
}
this.FileUpload1.SaveAs(Server.MapPath("Photo\\") + UpLoadPhotoName + "." + type);
HiddenField1.Value = "/zxyAdmin/Exhibit/Photo/" + UpLoadPhotoName + "." + type;
return true;
}
else
{ //不是合法格式做的处理
Page.ClientScript.RegisterStartupScript(GetType(), "scsp", "<script language='javascript'>alert('你图片上传的格式不正确!')</script>");
return false;
}
//} }
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货