string dir;
dir = System.Environment.CurrentDirectory;  //这样取到当前程序的目录:
结果:
C:\Documents and Settings\administration\My Documents\Visual Studio 2008\Projects\test3\test3\bin\Debug  
但是我想得到以下一个新的目录,应该怎么实现?
C:\Documents and Settings\administration\My Documents\Visual Studio 2008\Projects\test3\test3\xml
谢谢

解决方案 »

  1.   

    怎么设置 dir 这个变量为 ../../xml 我也知道这么处理,是不是还要增加其他的东西?
      

  2.   

                if (Directory.Exists("../../xml"))
                    dir = "../../xml";
      

  3.   

    上面方法可以解决你当前问题,但是从根本上的问题你没有解决。你改了之后用VS运行 或者双击Debug/bin/.exe文件运行不会有问题,但是你要知道最终你打包安装后所安装的文件就只有Debug/bin下面的文件。到时就找不到../../xml。如果你要建一个XML文件夹,你可以在Degug/bind下面建,或者你在解决方案里建,然后重新生成一下就可以了。最终还是在Deug/bin下面生成XML文件夹。
      

  4.   

    写反了  应该是Bin/Debug/
      

  5.   

    String Dir = System.Environment.CurrentDirectory;
    if (Directory.Exists("../../xml/ComConfig.xml"))
    Dir = "../../xml/ComConfig.xml";
    String strDir = @dir;未能找到路径“E:\项目\ComInterface\interfaceflatform\Com102\bin\Com102\Xml\ComConfig.xml”的一部分。
      

  6.   

    你把你的那个Xml\ComConfig.xml的完全路径贴出来看一下知道。
      

  7.   

    Xml\ComConfig.xml的路径在E:\项目\ComInterface\interfaceflatform\Com102\Xml
    程序的路径在               E:\项目\ComInterface\interfaceflatform\Com102\bin\Debug
    ../../xml根本就没有起到作用。
      

  8.   

    String strDir = System.Environment.CurrentDirectory;
    strDir=@"../../xml/ComConfig.xml";
    这样行了,谢谢大家,结贴了