System.Web.HttpException:将SaveAs方法配置为需要根目录路径,并且该路径不是根目录

时间:2019-06-19 06:33:16

标签: asp.net vb.net

我面临的错误是:

System.Web.HttpException: The SaveAs method is configured to require a rooted path, and the path '~\FileUpload\2019\HS-123.png' is not rooted.

我发现这里的代码有点奇怪:

   Dim folderPath1 As String = ("~\FileUpload\" & Today.Year.ToString & "\")
   If fileuploadSituation.HasFile Then
                    Dim extension As String = (Path.GetExtension(fileuploadSituation.FileName))

                    fileuploadSituation.SaveAs(Server.MapPath(folderPath1) & ID + extension)

   End If

此代码在这里工作正常。但不是此代码:

 If fileuploadSuggest.HasFile Then

                    Dim extension1 As String = (Path.GetExtension(fileuploadSuggest.FileName))


                    fileuploadSuggest.SaveAs(Server.MapPath(folderPath1) & ID + extension1)

 End If

它适用于fileuploadSituation,但不适用于fileUploadSuggest,即使它们使用相同的路径。有什么建议可以用来申请吗?

0 个答案:

没有答案