首页 > 解决方案 > 如何在Visual Studio项目c#中引用包含的文件

问题描述

我有一个使用 XSL 文件转换 XML 文件的窗口窗体项目。

当我调用 XSL 文件时,我使用特定的方法并将 XML 的路径传递给它:

myXslTransform.Load("...\\Trasformazione.xsl");

如何引用项目中包含的文件?因为当我发布它时,其他人没有相同的路径并且程序不起作用。

例如:

myXslTransform.Load("MyProject.Trasformazione.xsl");

标签: c#xmlvisual-studioxslt

解决方案


您可以将路径保存在 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)


推荐阅读