如何从RIA服务中的相对路径读取xml文件?

发布于 2024-09-25 21:55:05 字数 371 浏览 3 评论 0原文

我试图在 RIA 服务中读取 XML 文件,但收到以下错误。

查询“GetSummaryList”的加载操作失败。找不到路径“C:\WINDOWS\SYSTEM32\CoreResources\SumaryListDS.xml”的一部分。

我正在使用 Silverlight 4,它使用 RIA 服务。我正在尝试读取位于 bin\CoreResources 文件夹中的 SumaryListDS.xml。但是应用程序开始在 bin\CoreResources 下查找文件,它尝试从 C:\WINDOWS\SYSTEM32\CoreResources 读取它。

我只是想知道如何使用 Silverlight 前端的 RIA 服务中的相对路径读取文件?

谢谢, 维诺德

I am trying to read an XML file in RIA Service and I am getting the following error.

Load operation failed for query 'GetSummaryList'. Could not find a part of the path 'C:\WINDOWS\SYSTEM32\CoreResources\SumaryListDS.xml'.

I am using Silverlight 4 which is using RIA service. I am trying to read the SumaryListDS.xml located in the bin\CoreResources folder. But the application insted of looking for the file under bin\CoreResources, its trying to read it from C:\WINDOWS\SYSTEM32\CoreResources.

I am just wondering how to read a file using relative path in RIA Service with Silverlight front end?

Thanks,
Vinod

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森林很绿却致人迷途 2024-10-02 21:55:05

您应该能够使用 .. 转到上一个目录,例如 ../CoreResources/GetSummaryList.xml

You should be able to use .. to go up one directory, such as ../CoreResources/GetSummaryList.xml

绮筵 2024-10-02 21:55:05

这是我解决问题的方法。它在业务层的某一层中实现,可供各种客户端(ASP.NET、控制台应用程序、Windows 客户端、托管在 ASP.NET 内的 Silverlight)使用。因此,当调用 GetSummaryXml 时,以前

public DataSet GetSummaryXml()
{
    var dsReport = new DataSet("Report");
    var summaryListXmlPath = "CoreResources/SumaryListDS.xml";
    dsReport.ReadXml(summaryListXmlPath);
    return dsReport;
}

当我开始在 RIA 域服务中使用它以供 Silverlight 4 客户端使用时,我开始收到错误。

错误:

查询加载操作失败
'获取摘要列表'。找不到
路径的一部分
'C:\WINDOWS\SYSTEM32\CoreResources\SumaryListDS.xml'。

但 SumaryListDS.xml 位于 bin\CoreResources 中,而不是 WINDOWS\SYSTEM32\CoreResources

所以我将 GetSummaryXml 修改为...

public DataSet GetSummaryXml()
{
    var dsReport = new DataSet("Report");
    var currContext = HttpContext.Current;
    var summaryListXmlPath = "CoreResources/SumaryListDS.xml";
    if (currContext != null)
        summaryListSchemaPath = currContext.Server.MapPath(@"../bin/" + summaryListXmlPath);
    dsReport.ReadXml(summaryListXmlPath);
    return dsReport;
}

现在它工作正常。我不确定这是否是一个完美的解决方案。

Here is how I resolved my problem. Its been implemented in one of the layers of business tier, which can be used by variety of clients (ASP.NET, Console App, Windows Client, Silverlight hosted inside ASP.NET). So when GetSummaryXml is called, previously it used to be

public DataSet GetSummaryXml()
{
    var dsReport = new DataSet("Report");
    var summaryListXmlPath = "CoreResources/SumaryListDS.xml";
    dsReport.ReadXml(summaryListXmlPath);
    return dsReport;
}

I started getting an error when I started consuming it in RIA Domain Service to be used by Silverlight 4 client.

ERROR:

Load operation failed for query
'GetSummaryList'. Could not find a
part of the path
'C:\WINDOWS\SYSTEM32\CoreResources\SumaryListDS.xml'.

But SumaryListDS.xml located in the bin\CoreResources, not WINDOWS\SYSTEM32\CoreResources

So I modified GetSummaryXml to...

public DataSet GetSummaryXml()
{
    var dsReport = new DataSet("Report");
    var currContext = HttpContext.Current;
    var summaryListXmlPath = "CoreResources/SumaryListDS.xml";
    if (currContext != null)
        summaryListSchemaPath = currContext.Server.MapPath(@"../bin/" + summaryListXmlPath);
    dsReport.ReadXml(summaryListXmlPath);
    return dsReport;
}

And now its working fine. I am not sure if this is a perfect solution thou.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文