1.放在ajax.BeginForm里,不好使,同asp.net 表单中 fileupload控件不支持ajax差不多吧,如果异步的话可以借助jquery.form.js,很方便
2.
//上传文件
object fielLogoImg = Request.Files["fielLogoImg"];
if (fielLogoImg != null)
{
string fileExtension = string.Empty;
string filename = string.Empty; ;
string filePathName = string.Empty;
if (Request.Files["fielLogoImg"].ContentLength > 0 && Request.Files["fielLogoImg"].ContentLength <= 51200)
{
bool fileJudge = false;
string path = Server.MapPath(Framework.Configuration.UserFilePath + CurrentUser.UName);
string uploadFileName = Path.GetFileName(Request.Files["fielLogoImg"].FileName);
fileExtension = System.IO.Path.GetExtension(Request.Files["fielLogoImg"].FileName).ToLower();
filename = "Logo" + fileExtension;
string[] ae = { ".gif", ".bmp", ".jpg", ".jpeg", ".png", ".tif" };
for (int i = 0; i < ae.Length; i++)
{
if (fileExtension == ae[i])
{
fileJudge = true;
}
}
if (fileJudge)
{
filePathName = Path.Combine(path, filename);
Request.Files["fielLogoImg"].SaveAs(filePathName);
cvModel.LogUrl = "/../Files/Web/" + CurrentUser.UName + "/" + filename;
}
else
{
return Content("提示1:上传图片类型限制:" + ".gif|.bmp|.jpg|.jpeg|.png|.tif");
}
}
else
{
return Content("提示4:图片大小不超过100kb");
}
}
else
{
cvModel.LogUrl = "/../Files/Common/Web/Web1/Logo.png";//默认的图片;
}