我有一个HttpPostedFile对象,当我尝试通过另存为保存它,我得到这个异常System.Web.HttpException
SaveAs方法被配置为需要有根的路径,和该路径” ./tempUpload/4' 没有生根。
为什么?我该如何纠正呢?
路径应该是绝对路径,而不是相对URL。
使用Server.MapPath
方法从你的相对URL的绝对路径。
ASP.NET不喜欢您的路径点。尝试 'tempUpload / 4' 代替。
您可以使用此代码用于保存文件。
string trailingPath = Path.GetFileName(fileName+".wav");
string fullPath = Path.Combine(Server.MapPath("~/Recordings"), trailingPath ?? throw new InvalidOperationException());
file.SaveAs(fullPath);