【问题标题】:Could not find xml file找不到 xml 文件
【发布时间】:2012-12-22 21:57:43
【问题描述】:

我正在学习 wcf。在我的测试项目中,服务从 xml 文件中读取数据,然后将其发送给客户端。数据是“myClass”类型的数组。 服务类有一个功能 折叠 |复制代码

    private XDocument GetDB()
    {

        string filePath = "SampleDB.xml"           
        return XDocument.Load(filePath);
    }

此功能在我运行服务应用程序时起作用。但是当我从客户端调用服务时它不起作用。

位于 bin->debug 文件夹中的 xml 文件的副本。但是当我运行程序时,我看到这样的异常

找不到文件 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\SampleDB.xml'。

我该如何解决这个问题?

【问题讨论】:

    标签: c# xml wcf


    【解决方案1】:

    显然,提供文件的完整路径,应以 bin\debug\SampleDB.xml 结尾

    【讨论】:

      【解决方案2】:

      您必须使用Server.MapPath 指定xml 文件。

      string filePath = Server.MapPath("SampleDB.xml");
      

      这就是“Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\SampleDB.xml'”的解决方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-13
        • 1970-01-01
        • 2022-09-27
        • 2017-12-19
        • 1970-01-01
        • 2014-12-20
        • 1970-01-01
        相关资源
        最近更新 更多