Net to get the assembly path, net to get the path
The Assembly loaded from the memory, with no path
IIS path
Protectedvoid Page_Load (object sender, EventArgs e) { Response. Write ("Assembly path" + System. Reflection. Assembly. GetExecutingAssembly (). Location + "<BR/> "); Response. Write ("program domain path" + System. AppDomain. CurrentDomain. BaseDirectory + "<BR/> "); Response. Write ("module path" + System. Diagnostics. Process. GetCurrentProcess (). MainModule. FileName + "<BR/> "); Response. Write ("RunTime path" + HttpRuntime. BinDirectory + "<BR/> "); } |
Output
Assembly path C: \ Windows \ Microsoft. NET \ Framework64 \ v4.0.30319 \ Temporary ASP. NET Files \ test \ 02a51a22 \ 1e6b2246 \ assembly \ dl3 \ 3464d812 \ Users \ WebApplication3.dll Program domain path d: \ Users \ zwx \ Documents \ visual studio 2015 \ Projects \ WebApplication3 \ WebApplication3 \ Module path: c: \ windows \ system32 \ inetsrv \ w3wp.exe Runtime path d: \ Users \ zwx \ Documents \ visual studio 2015 \ Projects \ WebApplication3 \ WebApplication3 \ bin \ |
Path in WINFORM
Console. Write ("Assembly path" + System. Reflection. Assembly. GetExecutingAssembly (). Location + "\ r \ n "); Console. Write ("program domain path" + System. AppDomain. CurrentDomain. BaseDirectory + "\ r \ n "); Console. Write ("module path" + System. Diagnostics. Process. GetCurrentProcess (). MainModule. FileName + "\ r \ n "); Console. Write ("RunTime path" + System. Windows. Forms. Application. ExecutablePath + "\ r \ n "); |
Output
Assembly path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bi N \ Debug \ ZY.Cloud.Front.GatewayService.exe Program domain path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bi N \ Debug \ Module path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bin \ Debug \ ZY.Cloud.Front.GatewayService.exe Runtime path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bi N \ Debug \ ZY.Cloud.Front.GatewayService.exe |
Path in Service
Assembly path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bin \ Debug \ ZY.Cloud.Front.GatewayService.exe Program domain path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bin \ Debug \ Module path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bin \ Debug \ ZY.Cloud.Front.GatewayService.exe Runtime path D: \ CodeCard \ Front Server \ integrated Front Server \ ZY. Cloud. Front. GatewayService \ bin \ Debug \ ZY.Cloud.Front.GatewayService.exe |
When operating files, it is best to display the specified path in the Code. After all, the location of the Assembly itself is uncontrollable. We recommend that you use the program domain path or ExecutablePath.