代码之家  ›  专栏  ›  技术社区  ›  Mike

在Windows窗体应用程序中获取应用程序文件路径

  •  0
  • Mike  · 技术社区  · 14 年前

    Application.CommonAppDataPath 但这会返回路径的末尾是1.0.0.0。

    Applicaiton.StartupPath 但这将返回在末尾带有\bin\debug的路径

    是否可以只获取主文件目录的路径而不在末尾附加任何内容?

    3 回复  |  直到 14 年前
        1
  •  1
  •   Community CDub    7 年前

    Application.StartupPath 正在返回路径 \bin\debug 在你的代码运行的地方,至少在你的开发机器上。

    如果您要将其从开发机器中部署,那么 应用程序.StartupPath

    bin\debug 问题?好吧,一个肮脏的黑客就是 .

    在这种情况下,如果需要检查是否在调试器中运行,请参见 this question

        2
  •  0
  •   pyCoder    14 年前

    Dim aPath As String 
    Dim aName As String 
    
    aName = _
      System.Reflection.Assembly.GetExecutingAssembly. _
      GetModules()(0).FullyQualifiedName    
    
    aPath = System.IO.Path.GetDirectoryName(aName) 
    
        3
  •  0
  •   Javed Akram    14 年前

    你可以用

    Application.ExecutablePath; 提供完整路径,包括可执行文件名

    Application.StartupPath; 对于您当前正在运行的应用程序路径目录(不带文件名)