SaveAs方法配置为需要根路径,并且路径'〜\\ images \\ 594083964.jpg'未植根

7 c# asp.net exception

SaveAs方法配置为需要根路径,路径'〜\ images\594083964.jpg'不是root.描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.

例外细节:

System.Web.HttpException:SaveAs方法配置为需要根路径,路径'〜\ images\594083964.jpg'不是root.

来源错误:

Line 27:     {
Line 28: 
Line 29:         fu1.SaveAs(@"~\\images\\" + i + fu1.FileName.Substring(fu1.FileName.Length - 4, 4));
Line 30: path = "~\\images\\"+i + fu1.FileName.Substring(fu1.FileName.Length-4,4);
Line 31: }
Run Code Online (Sandbox Code Playgroud)

源文件:e:\ PEOPLE\Ravi \new data\WebSite1\signup.aspx.cs行:29

MPr*_*ard 21

您要保存的路径是相对URL.您需要保存到本地文件路径(或完整的网络路径).

尝试:

string relativePath = @"~\images\"+ i + Path.GetExtension(fu1.FileName);
fu1.SaveAs(Server.MapPath(relativePath));
Run Code Online (Sandbox Code Playgroud)

(Path.GetExtension(string)将处理不是3个字符的文件扩展名)