zoukankan      html  css  js  c++  java
  • Net中获取程序集路径

     

    从内存中加载的程序集,无路径

     

    IIS中路径

    protected void Page_Load(object sender, EventArgs e)

    {

    Response.Write("程序集路径"+System.Reflection.Assembly.GetExecutingAssembly().Location+"<BR/>");

    Response.Write("程序域路径"+System.AppDomain.CurrentDomain.BaseDirectory + "<BR/>");

    Response.Write("模块路径"+System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName + "<BR/>");

    Response.Write("运行时路径"+HttpRuntime.BinDirectory + "<BR/>");

    }

     

     

     

    输出

     

     

    程序集路径C:WindowsMicrosoft.NETFramework64v4.0.30319Temporary ASP.NET Files est2a51a221e6b2246assemblydl33464d81241e5e6a4_2697d301WebApplication3.dll
    程序域路径d:UserszwxDocumentsvisual studio 2015ProjectsWebApplication3WebApplication3
    模块路径c:windowssystem32inetsrvw3wp.exe
    运行时路径d:UserszwxDocumentsvisual studio 2015ProjectsWebApplication3WebApplication3in

     

     

     

    WINFORM中路径

    Console.Write("程序集路径" + System.Reflection.Assembly.GetExecutingAssembly().Location + " ");

    Console.Write("程序域路径" + System.AppDomain.CurrentDomain.BaseDirectory + " ");

    Console.Write("模块路径" + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName + " ");

    Console.Write("运行时路径" + System.Windows.Forms.Application.ExecutablePath+ " ");

     

    输出

    程序集路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicei

    nDebugY.Cloud.Front.GatewayService.exe

    程序域路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicei

    nDebug

    模块路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicein

    DebugY.Cloud.Front.GatewayService.exe

    运行时路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServicei

    nDebugY.Cloud.Front.GatewayService.exe

     

     

    服务中路径

    程序集路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebugY.Cloud.Front.GatewayService.exe

    程序域路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebug

    模块路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebugY.Cloud.Front.GatewayService.exe

    运行时路径D:CodeCard前置伺服器综合前置伺服器Y.Cloud.Front.GatewayServiceinDebugY.Cloud.Front.GatewayService.exe

     

     

     

    操作文件时,最好在代码中显示指定路径,毕竟程序集自身的位置是不可控的。推荐使用程序域路径或ExecutablePath

  • 相关阅读:
    ArcGIS python field 字段
    shapefile 输出的地理处理注意事项
    arcgis python RefreshActiveView CLEAR_SELECTION
    arcgis python 判断是数据库或是文件夹
    Arcengine获得arcgis安装的版本
    python获得坐标系信息
    修复几何 (数据管理)原理
    Python获取指定目录下所有子目录、所有文件名
    python的路径
    用Python写一个将Python2代码转换成Python3代码的批处理工具
  • 原文地址:https://www.cnblogs.com/QinQouShui/p/8365547.html
Copyright © 2011-2022 走看看