“/tthr”应用程序中的服务器错误。
未能映射路径“/hr/img/10537545.jpg”。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 未能映射路径“/hr/img/10537545.jpg”。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 代码:
string newext2="";
string newname2=""; if((uploadfile.PostedFile!=null)&&(uploadfile.PostedFile.FileName.Trim()!=""))
{
string nam = uploadfile.PostedFile.FileName ;
int i= nam.LastIndexOf(".");
newext2 =nam.Substring(i);
DateTime now = DateTime.Now;
newname2 =now.DayOfYear.ToString() + uploadfile.PostedFile.ContentLength.ToString();
uploadfile.PostedFile.SaveAs(Server.MapPath("\\hr\\img\\"+newname2+newext2)); //报错行
}
注意:
Server.MapPath("\\hr\\img\\"+newname2+newext2); 里面路径不管怎么改,即使不用hr字样,还是报 未能映射路径“/hr/img/10537545.jpg”错误,从昨天一直调到现在,郁闷了,哪位C#强人帮帮忙吧!!先谢谢了!
未能映射路径“/hr/img/10537545.jpg”。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: 未能映射路径“/hr/img/10537545.jpg”。
源错误:
执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。 代码:
string newext2="";
string newname2=""; if((uploadfile.PostedFile!=null)&&(uploadfile.PostedFile.FileName.Trim()!=""))
{
string nam = uploadfile.PostedFile.FileName ;
int i= nam.LastIndexOf(".");
newext2 =nam.Substring(i);
DateTime now = DateTime.Now;
newname2 =now.DayOfYear.ToString() + uploadfile.PostedFile.ContentLength.ToString();
uploadfile.PostedFile.SaveAs(Server.MapPath("\\hr\\img\\"+newname2+newext2)); //报错行
}
注意:
Server.MapPath("\\hr\\img\\"+newname2+newext2); 里面路径不管怎么改,即使不用hr字样,还是报 未能映射路径“/hr/img/10537545.jpg”错误,从昨天一直调到现在,郁闷了,哪位C#强人帮帮忙吧!!先谢谢了!
uploadfile.PostedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("~/hr/img/") +newname2+newext2);
uploadfile.PostedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("/hr/img/") +newname2+newext2);
///定义实际文件对象,保存上载的文件。
FileStream f = new FileStream(Server.MapPath(".") + "\\" + "UpLoadFiles\\"
+ FileName, FileMode.Create);
这样行吗?
试试
即使不用hr字样,还是报未能映射路径“/hr/img/10537545.jpg”错,
===
你用缓存了?
也或是在你的临时文件夹下面的一些临时文件没有删除,你自己清理以下临时文件夹。
我以前也出现类似的情况,后来我重新建个页面,取个不同的名字,把代码靠过来才好的……
文件都没生成,你怎么映射。你应该映射目录
先创建目录再保存文件
{
System.IO.Directory.CreateDirectory(Server.MapPath("file"));
}
System.IO.Directory.Delete(Server.MapPath("file"),true);
//删除文件夹以及文件夹中的子目录,文件判断文件的存在if (System.IO.File.Exist(Server.MapPath("~/Back/Data.xml"))
{
//存在文件
}
else
{
//不存在文件
Directory.Create(Server.MapPath("~/Back/Data.xml"));//创建该文件
}
if(Directory.Exist(Server.MapPath("~/Back")))
{
//存在目录
}
else
{
//不存在目录
Directory.CreateDirectory(Server.MapPath("~/Back")); //创建该目录
}
if(File.Exist(Server.MapPath("~/Back/Data.xml")))
{
//存在文件
}
else
{
//不存在文件
Directory.Create(Server.MapPath("~/Back/Data.xml"));//创建该文件
}
Server.MapPath("~/Back")用于得到该虚拟目录或虚拟文件的绝对路径
if (Directory.Exists(System.Web.HttpContext.Current.Request.MapPath("../picture/")))
{
//存在目录
}
else
{
//不存在目录
Directory.CreateDirectory(System.Web.HttpContext.Current.Request.MapPath("../picture/")); //创建该目录
}
if (File.Exists(System.Web.HttpContext.Current.Request.MapPath("../picture/") + fileName))
{
//存在文件
Response.Write("文件已经存在");
return false;
}
else
{
//不存在文件
//Directory.Create(Server.MapPath("~/Back/Data.xml"));//创建该文件
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("../picture/") + fileName);
}