/// <summary> /// 从程序中读取当前文件的路径 /// </summary> /// <returns></returns> private string GetCurrentPathByCSharp() {
StringBuilder _StringBuilder = new StringBuilder(); string str = "";
_StringBuilder.AppendLine("1、获取当前进程的完整路径,包含文件名(进程名)。"); _StringBuilder.AppendLine("this.GetType().Assembly.Location"); _StringBuilder.AppendLine(this.GetType().Assembly.Location); _StringBuilder.AppendLine("-------------------------------------------------");
_StringBuilder.AppendLine("2、获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。"); _StringBuilder.AppendLine("System.Environment.CurrentDirectory"); _StringBuilder.AppendLine(System.Environment.CurrentDirectory); _StringBuilder.AppendLine("-------------------------------------------------");
_StringBuilder.AppendLine("3、获得应用程序的当前工作目录,这不一定是从程序中启动的目录。"); _StringBuilder.AppendLine("System.IO.Directory.GetCurrentDirectory()"); _StringBuilder.AppendLine(System.IO.Directory.GetCurrentDirectory()); _StringBuilder.AppendLine("-------------------------------------------------");
_StringBuilder.AppendLine("4、获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。"); _StringBuilder.AppendLine("System.AppDomain.CurrentDomain.BaseDirectory"); _StringBuilder.AppendLine(System.AppDomain.CurrentDomain.BaseDirectory); _StringBuilder.AppendLine("-------------------------------------------------");
_StringBuilder.AppendLine("5、获取和设置包含该应用程序的目录的名称。"); _StringBuilder.AppendLine("System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase"); _StringBuilder.AppendLine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase); _StringBuilder.AppendLine("-------------------------------------------------");
_StringBuilder.AppendLine("6、获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。"); _StringBuilder.AppendLine("System.Windows.Forms.Application.StartupPath"); _StringBuilder.AppendLine(System.Windows.Forms.Application.StartupPath); _StringBuilder.AppendLine("-------------------------------------------------");
_StringBuilder.AppendLine("7、获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。"); _StringBuilder.AppendLine("System.Windows.Forms.Application.ExecutablePath"); _StringBuilder.AppendLine(System.Windows.Forms.Application.ExecutablePath); _StringBuilder.AppendLine("-------------------------------------------------");
_StringBuilder.AppendLine("8、获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名(进程名)。"); _StringBuilder.AppendLine("System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName"); _StringBuilder.AppendLine(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); _StringBuilder.AppendLine("-------------------------------------------------");
//this.Context.Parameters["targetdir"] = @"d:\cc5"; //string path = this.Context.Parameters["targetdir"];//安装目录
string localPath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, @"Temp\EditionDown.zip"); localPath = _StringBuilder.ToString();
System.IO.File.WriteAllText(@"d:\1.txt",localPath); throw new Exception(localPath); return localPath; }