HttpPostedFile.SaveAs error, rooted path?

送分小仙女□ 提交于 2019-12-24 05:59:29

问题


I have an HttpPostedFile object, when I try saving it via SaveAs I get this exception System.Web.HttpException

The SaveAs method is configured to require a rooted path, and the path './tempUpload/4' is not rooted.

Why? how do I correct it?


回答1:


The path should be an absolute path, not a relative url.

Use the Server.MapPath method to get the absolute path from your relative url.




回答2:


ASP.NET doesn't like the dot in your path. Try 'tempUpload/4' instead.




回答3:


You can use this code for saving a file.

string trailingPath = Path.GetFileName(fileName+".wav");
string fullPath = Path.Combine(Server.MapPath("~/Recordings"), trailingPath ?? throw new InvalidOperationException());
file.SaveAs(fullPath);


来源:https://stackoverflow.com/questions/1089713/httppostedfile-saveas-error-rooted-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!