访问XSLT文件来自同一个项目的资源? [英] Access an XSLT file as resource from same project?

查看:128
本文介绍了访问XSLT文件来自同一个项目的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要加载和使用将XML文件的XSLT文件。我已经添加文件到同一个项目作为使用它的代码,并把它放在资源文件夹,并设置生成操作为资源。

I have an XSLT file that I want to load and use to transform an XML file. I've added the file to the same project as the code that uses it and put it in the "Resources" folder and set the Build Action to "Resource".

这是一个尝试访问该文件的代码:

This is the code that tries to access the file:

        XslCompiledTransform myXslTransform = new XslCompiledTransform();

        myXslTransform.Load(@"[projectName];component/Resources/OrderManagement/OrderOverview.xslt");



...其中[项目]是该项目的名称。然而,这似乎并没有工作。我打得周围不同的路径,但不知何故,我似乎并没有得到它的权利。我敢肯定,这只是一件小事,但没有我已经在互联网上找到(或这里)的文章都帮助了我。

... where [projectName] is the name of the project. However this doesn't seem to work. I've played around with different paths, but somehow I don't seem to get it right. I'm sure it's just a little thing, but none of the articles I have found on the internet (or here) have helped me.

谁能帮助?

推荐答案

一个同事帮我找到一个解决方案。我们通过项目的属性添加的资源,这样我就可以很容易地访问其内容,并用下面的代码。

A co-worker has helped me find a solution. We added the resource via the properties of the project, so that I can access its content easily and used the following code.

using (var reader = new StringReader(Resources.OrderOverview)) {
  using (XmlReader xmlReader = XmlReader.Create(reader)) {
    myXslTransform.Load(xmlReader);
    myXslTransform.Transform(fileName, arguments, xmlTextWriter);
  }
}

这是非常相似,outcoldman与微妙的建议区别该资源不同访问。

This is very similar to what outcoldman suggested with the subtle difference that the resource is accessed differently.

这篇关于访问XSLT文件来自同一个项目的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆