我是windorm的程序,
string xmlFilePath = Directory.GetCurrentDirectory();
XmlDocument doc = new XmlDocument();
doc.Load(xmlFilePath);
然而在运行到doc.Load(xmlFilePath);的时候却提示:对路径“XXXX”的访问被拒绝。
我在网上了下,很多出问题的是webform的,而winform很少见到。
这个问题该怎么解决呢?

解决方案 »

  1.   

    Directory.GetCurrentDirectory
    方法得到的是文件夹路径
    doc.Load()方法参数是文件的路径
      

  2.   

    你是在在运行时吗?还是在程序当前运行的文件下面.
    以前这样用过,就是当前程序集当前目录
         string assemblyFilePath = Assembly.GetExecutingAssembly().Location;
                string assemblyDirPath = Path.GetDirectoryName(assemblyFilePath);
                string configFilePath = assemblyDirPath + "\\log4net.config";
              XmlDocument doc = new XmlDocument(); 
    doc.Load(configFilePath); 你要确定路径对不对.权限对不对
      

  3.   

    Directory.GetCurrentDirectory(); 是获取文件夹路径,Load需要文件,当然会报错