HttpPostedFile.SaveAs错误,扎根路径?

问题描述 投票:1回答:3

我有一个HttpPostedFile对象,当我尝试通过另存为保存它,我得到这个异常System.Web.HttpException

SaveAs方法被配置为需要有根的路径,和该路径” ./tempUpload/4' 没有生根。

为什么?我该如何纠正呢?

c# asp.net exception-handling
3个回答
3
投票

路径应该是绝对路径,而不是相对URL。

使用Server.MapPath方法从你的相对URL的绝对路径。


0
投票

ASP.NET不喜欢您的路径点。尝试 'tempUpload / 4' 代替。


0
投票

您可以使用此代码用于保存文件。

string trailingPath = Path.GetFileName(fileName+".wav");
string fullPath = Path.Combine(Server.MapPath("~/Recordings"), trailingPath ?? throw new InvalidOperationException());
file.SaveAs(fullPath);
© www.soinside.com 2019 - 2024. All rights reserved.