C# 需要获取应用程序文件夹
我需要获取我的应用程序目录并向该路径添加文件名。所以我就这样用C# 需要获取应用程序文件夹,c#,C#,我需要获取我的应用程序目录并向该路径添加文件名。所以我就这样用 String kofaxTextFilePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(File)).CodeBase) + "\\KofaxBatchHistory.txt" 所以它会给出这样一条路径 “file:\\C:\\Documents and Settings\\MyApplication\\ KofaxBatchHistory.txt” 但我只需要
String kofaxTextFilePath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(File)).CodeBase) + "\\KofaxBatchHistory.txt"
所以它会给出这样一条路径
“file:\\C:\\Documents and Settings\\MyApplication\\ KofaxBatchHistory.txt”
但我只需要
C:\\Documents and Settings\\MyApplication\\ KofaxBatchHistory.txt
没有对该字符串执行任何操作,是否有任何方法可以直接获取它?尝试
汇编.Location
Assembly.GetAssembly(typeof(File)).Location
或者(更好的是):
请参阅Environment.SpecialFolder枚举 您可能正在查找SpecialFolder.CommonApplicationData
typeof(File).Assembly.Location
string myDir = System.Reflection.Assembly.GetExecutingAssembly().Location;
myDir = System.IO.Path.GetDirectoryName(myDir);
String kofaxTextFilePath = System.IO.Path.Combine(myDir, "KofaxBatchHistory.txt");