c# - 如何在Visual Studio项目c#中引用包含的文件
问题描述
我有一个使用 XSL 文件转换 XML 文件的窗口窗体项目。
当我调用 XSL 文件时,我使用特定的方法并将 XML 的路径传递给它:
myXslTransform.Load("...\\Trasformazione.xsl");
如何引用项目中包含的文件?因为当我发布它时,其他人没有相同的路径并且程序不起作用。
例如:
myXslTransform.Load("MyProject.Trasformazione.xsl");
解决方案
您可以将路径保存在 App.config
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<appSettings>
<add key="FilePath" value="...\\MyProject.Trasformazione.xsl" />
</appSettings>
</configuration>
在代码中:
myXslTransform.Load(System.Configuration.ConfigurationManager.AppSettings.Get("FilePath"));
其他人需要编辑配置文件(AppName.exe.Config)
推荐阅读
- html - 如何使边框底部颜色高于边框右侧颜色?
- php - 如何将流 php://temp 内容放入 html
- reactjs - Reactjs 渲染大量组件很慢
- sql - 将行转换为列值。具有多个代码值的唯一 ID
- pygame - 运行 Street pyghter 的问题 - 1.2
- bash - 仅尾随命令的输出
- google-chrome - chrome跟踪文件中对nodeId,frame,frameTreeNodeId,layerId和layerTreeId(以及其他)的每个引用之间的关系是什么
- javascript - 在等待服务器端代码时显示加载器(没有空白页)
- ios - UITextView 设置 NSTextAttachment 图像导致性能滞后、缓慢问题
- c++ - 我的 C++ 代码不接受在键盘上输入的字符到数组中