问题
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