在窗体控件库中有一个xml文件:项目目录\data\default.xml,如何通过程序获取这个xml的路径?

解决方案 »

  1.   

    尝试:
    Application.StartupPath\data\default.xml
      

  2.   

    Application.StartupPath+@"\data\default.xml";
      

  3.   

    没有Application,是窗体控件库
      

  4.   

    引用 System.Windows.Forms.dll就有了。
      

  5.   

    如果是在Windows程序中:
    放在bin目录下面:string path=@"data/default.xml";这样可以获取这个文件
    如果是Web程序:string path="~/data/default.xml"; Server.Mapth(path);这个可以获得物理路径
      

  6.   

    AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"data/default.xml";
      

  7.   

    LZ你先添加需要的空间,再引用控件:system.windows.form.控件的相应DLL名字
      

  8.   

    AppDomain.CurrentDomain.SetupInformation.ApplicationBase
    Application.StartupPath
    得到的都是"C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\"
    并非项目的路径
      

  9.   

          string str = Assembly.GetExecutingAssembly().GetName().CodeBase; 
          if (str.ToLower().IndexOf("file:///") >= 0) 
          { 
              str = str.Substring(8, str.Length - 8); 
          } 
          string path = System.IO.Path.GetDirectoryName(str);
    这个不知道有用吗?试试吧