解决方案目录如下图。DAL为类库,被MVC项目App调用。Paramater.xml在DAL内。请问,DAL内的C#代码如何能够读取到Paramater.xml?

解决方案 »

  1.   

    DAL读取本项目下的文件有什么问题吗?写好路径就行了
      

  2.   

    string myXmlPath = (System.IO.Path.GetDirectoryName(myCode) + "\\DAL.xml").Remove(0,6).Replace("\\", "/");返回的已经是DAL.xml的全路径了。能不能来份实在的代码?
      

  3.   

    把那个XML放到执行项目下,代码不用动
    或者
    将XML使用embed方式嵌入,然后读取嵌入资源
     // 在当前程序集中查找嵌入的XML
                Assembly assembly = Assembly.GetExecutingAssembly();
                // 取出资源到流中
                using (Stream stream = assembly.GetManifestResourceStream(name))
                {
                    XmlDocument xmldoc = new XmlDocument();
                    xmldoc.Load(stream);
                    return xmldoc;
                }