【问题标题】:C:/Users/... is a physical path, but a virtual path was expectedC:/Users/... 是物理路径,但应该是虚拟路径
【发布时间】:2014-02-06 12:20:21
【问题描述】:
PhotoUpload.SaveAs(Server.MapPath("C:\\Users\\Renu\\Documents\\Visual Studio 2010\\WebSites\\matrimony\\App_Data\\images"+filename));

这里,PhotoUpload 是 FileUpload 组件的名称,filename 是一个简单的字符串对象。 PhotoUpload 的内容应保存在 App_Data 文件夹下名为“images”的文件夹中。但执行后,我得到以下错误:

C:/Users/Renu/Documents/Visual Studio 2010/WebSites/matrimony/App_Data/images

是物理路径,但应该是虚拟路径。我不知道如何解决这个错误。

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    ASP.NET 指南MapPath

    PhotoUpload.SaveAs(Server.MapPath(@"~\App_Data\images\"+filename));
    

    在哪里filename = "myFile.png"

    使用 @ 提供literal string

    【讨论】:

    • PhotoUpload.SaveAs(Server.MapPath(@"~\App_Data\images"+filename));
    • 您需要授予网站写入文件夹的权限。
    • 可能您缺少尾随 \
    • 权限相关部分怎么做??
    • 是的,那么你需要一个尾随反斜杠,就像我上面的回答 PhotoUpload.SaveAs(Server.MapPath(@"~\App_Data\images\"+filename));
    【解决方案2】:

    这样写:

    * ~ 获取网站的路径 我假设您的网站路径是 C:\Users\Renu\Documents\Visual Studio 2010

    PhotoUpload.SaveAs(Server.MapPath("~\\App_Data\\images"+filename)));
    

    【讨论】:

    • 婚姻是项目的名称。
    猜你喜欢
    • 1970-01-01
    • 2013-03-30
    • 1970-01-01
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多