private void UploadPhoto() { string script = string.Empty; if ((filPhoto.PostedFile != null) && (filPhoto.PostedFile.ContentLength > 0)) { if (!IsValidImageFile(filPhoto)) { script = string.Format(SCRIPT_TEMPLATE, "The uploaded file is not a valid image file.", "true"); } } else { script = string.Format(SCRIPT_TEMPLATE, "Please specify a valid file.", "true"); } if (string.IsNullOrEmpty(script)) { //Uploaded file is valid, now we can do whatever we like to do, copying it file system, //saving it in db etc. //Your Logic goes here //filPhoto.PostedFile.SaveAs(Server.MapPath("") + "upfiles/1.jpg"); string fileName; fileName = DateTime.Now.ToFileTime()+System.IO.Path.GetExtension(filPhoto.PostedFile.FileName); filPhoto.PostedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("upfiles/") + fileName); if (Session["upfiles"] != null) { Session.Remove("upfiles"); } Session.Add("upfiles", "upfiles/" + fileName); script = string.Format(SCRIPT_TEMPLATE, "Photo uploaded." + fileName, "false"); } //Now inject the script which will fire when the page is refreshed. ClientScript.RegisterStartupScript(this.GetType(), "uploadNotify", script); }
楼主附件大小是不是超过了2M,如果2M之内的可以上传,那就是win2003默认限制的缘故了,解决如下: 1.先在服务里关闭 iis admin service 服务 2.找到 windows\system32\inetsrv\ 下的 metabase.xml 文件,找到 ASPMaxRequestEntityAllowed 节点修改其值 3.存盘,然后重启 iis admin service 服务
{
string script = string.Empty; if ((filPhoto.PostedFile != null) && (filPhoto.PostedFile.ContentLength > 0))
{
if (!IsValidImageFile(filPhoto))
{
script = string.Format(SCRIPT_TEMPLATE, "The uploaded file is not a valid image file.", "true");
}
}
else
{
script = string.Format(SCRIPT_TEMPLATE, "Please specify a valid file.", "true");
} if (string.IsNullOrEmpty(script))
{
//Uploaded file is valid, now we can do whatever we like to do, copying it file system,
//saving it in db etc. //Your Logic goes here
//filPhoto.PostedFile.SaveAs(Server.MapPath("") + "upfiles/1.jpg"); string fileName;
fileName = DateTime.Now.ToFileTime()+System.IO.Path.GetExtension(filPhoto.PostedFile.FileName);
filPhoto.PostedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("upfiles/") + fileName); if (Session["upfiles"] != null)
{
Session.Remove("upfiles");
} Session.Add("upfiles", "upfiles/" + fileName); script = string.Format(SCRIPT_TEMPLATE, "Photo uploaded." + fileName, "false");
} //Now inject the script which will fire when the page is refreshed.
ClientScript.RegisterStartupScript(this.GetType(), "uploadNotify", script);
}
1.先在服务里关闭 iis admin service 服务
2.找到 windows\system32\inetsrv\ 下的 metabase.xml 文件,找到 ASPMaxRequestEntityAllowed 节点修改其值
3.存盘,然后重启 iis admin service 服务
asp.net帐户给了没?
文件夹是否存在?给一个everyone完全控制的权限试试。
everyone给了,也不行。
所有我就没有思路了,哪位可以给个思路,方向。
if (string.IsNullOrEmpty(script))
这个条件去掉看看
也就是 这条语句为 false
if ((filPhoto.PostedFile != null) && (filPhoto.PostedFile.ContentLength > 0))程序没有报错。
原因是什么呢
原因是什么呢
<form id="frmUpload" method="post" enctype="multipart/form-data" runat="server">
有没有enctype="multipart/form-data"