我在Mono + Apache2上运行ASP.NET时遇到了一个问题。 我把FileUpload控件的页面,当点击按钮上传文件时,它会抛出一个异常:单声道文件上传控制
找不到路径的一部分“/var/www/www.mysite.com/upload /headImage/uid_1.jpg”。
描述:HTTP 500.错误处理请求。
堆栈跟踪:
System.IO.DirectoryNotFoundException:找不到路径 “/var/www/www.mysite.com/upload/headImage/uid_1.jpg” 的一部分。在System.Web.UI的System.Web.HttpPostedFile.SaveAs(System.String文件名)[0x00000]处:0 中的System.IO.File.Delete(System.String path)[0x00000]处的 处:0 。 WebControls.FileUpload.SaveAs(System.String文件名)[0x00000] in::0 at WebApplication.users.ImageUpload.btnUpload_Click(System.Object sender,> System.EventArgs e)[0x00000] in:0 at System.Web在System.Web.UI.WebControls.Button.RaisePostBackEvent(System.String eventArgument)中的.UI.WebControls.Button.OnClick(System.EventArgs e)[0x00000]中的:0 >:[0x00000]:0 。 Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent>(System.String eventArgument)[0x00000] in:0 at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,> Sys在System.Web.UI.Page.RaisePostBackEvents()[0x00000]中:0 在System.Web.UI.Page.ProcessRaiseEvents()[0x00000]中:0 在System.Web.UI.Page.InternalProcessRequest()[0x00000]在:0 在System.Web.UI.Page.ProcessRequest(System.Web.HttpContext上下文)[0x00000]在:0
我确定路径“/var/www/www.mysite.com/upload/headImage/”存在并且已经是chmod 766,并且该文件夹中不存在“uid_1.jpg”。
的源代码:
string fileName = "uid_1.jpg";
string imageUrl = "/upload/headImage/" + fileName;
fileName = Path.Combine(Server.MapPath("~/upload/headImage/"), fileName);
if (File.Exists(fileName))
{
File.Delete(fileName);
}
upload.SaveAs(fileName);
谁能告诉该怎么办? 谢谢。
但我想也许这是最好的方法,其他人可以告诉我一个更好的解决方案? – zhoufoxcn 2012-08-10 00:33:04