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

  • 相关阅读:
    jquery实现奇偶行赋值不同css值
    Android短信批量插入速度优化的思考与尝试
    Android短信列表的时间显示
    短信优先级及有效期
    模拟器收短信和接电话的方法
    Android:Perferences的使用
    留个脚印
    Android电池电量更新 BatteryService(转)
    Android号码匹配位数修改
    CDMA SMS pdu解码
  • 原文地址:https://www.cnblogs.com/QinQouShui/p/8365547.html
Copyright © 2011-2022 走看看