zoukankan      html  css  js  c++  java
  • 获取文件路径

        /// <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;         }

  • 相关阅读:
    D1
    测试 Collectors 类中相关 API,以及 Collector 接口中 Characteristics 的枚举值
    Servlet 整合 freemarker、如何在 freemarker 中自定义标签
    webLogic javaweb 路径问题 Not allowed to load local resource
    高复用、高兼容的 ajaxForm 上传文件
    Extjs 4+ 中的 combobox 的级联
    Echarts中关于雷达图极坐标值相差过大时的图像展示问题
    java 使用poi操作Excel(2003,2007)实现数据批量导入的一般思路
    java 使用poi操作Excel表格(2003,2007)实现数据的批量导出
    Ext3.4 表格基本操作
  • 原文地址:https://www.cnblogs.com/mingyongcheng/p/2985113.html
Copyright © 2011-2022 走看看