using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.IO;
namespace Austec.ToolCollection
{
public class App
{
// 获取程序当前路径
public static string GetPath()
{
string fullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase;
string fullAppPath = Path.GetDirectoryName(fullAppName);
if (fullAppPath.StartsWith("file:"))
{
fullAppPath = fullAppPath.Substring(6);
}
if ( fullAppPath.Substring(fullAppPath.Length-1,1)!="//")
{
fullAppPath += "//";
}
return (fullAppPath);
}
}
}
本文介绍了一个简单的C#方法,用于获取当前运行程序的完整路径。该方法首先通过反射获取程序集的信息,然后使用Path类来解析目录名。此外,还处理了路径字符串的一些常见情况,如去掉不必要的前缀和确保路径以斜杠结尾。
5417

被折叠的 条评论
为什么被折叠?



