C# 获取程序路径

1.System.Reflection.Assembly.GetExecutingAssembly().Location

获取当前工程,比如DLL或者应用程序的目录。因为程序调用的DLL,有可能在任意一个文件夹,这方法能获取当前调用的DLL对应的路径。

2.Application.Current.StartupUri和Application.StartupPath

都是获取程序启动路径,区别是基类System.Windows和System.Windows.Forms

3.System.AppDomain.CurrentDomain.BaseDirectory

获取程序的基目录

以上是个人常用到的路径,完整的路径获取,可以参考其它博客:

http://www.cnblogs.com/netlyf/archive/2011/06/22/2086718.html

时间: 2024-08-24 00:15:58

C# 获取程序路径的相关文章

.Net下获取程序路径的方法

//方法一: string sPath = System.IO.Path.GetDirectoryName(this.Page.Request.PhysicalPath); //方法二:("images/")是当前虚拟目录下的任意目录 sPath = System.Web.HttpContext.Current.Request.MapPath("images/"); //方法三: sPath = Page.Server.MapPath("images/&q

获取当前程序路径

1. 本来想用java中的方式的,网上查到一些信息,我的测试代码如下: 1 String str = System.getProperty("java.class.path"); 2 String strUsrDir = System.getProperty("usr.dir"); 3 URL url = this.getClass().getResource(""); // **Test1.class 即 Class.forName("

delphi根据进程PID获取程序所在路径的函数(用OpenProcess取得句柄,用GetModuleFileNameEx取得程序名)

uses psapi; {根据进程PID获取程序所在路径的函数}function GetProcessExePath(PID: Cardinal): string;varpHandle: THandle;buf: array[0..MAX_PATH] of Char;begin{获取进程句柄}pHandle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PID);{获取进程路径}GetModuleFileN

C#应用程序获取项目路径的方法总结

一.非Web程序 //基目录,由程序集冲突解决程序用来探测程序集 1.AppDomain.CurrentDomain.BaseDirectory //当前工作目录的完全限定路径2.Environment.CurrentDirectory //当前应用程序的 /bin 目录的路径3.HttpRuntime.BinDirectory 二.Web程序 假设Web项目根目录为:"D:\TestPart\WebDirectoryTest". 1.HttpContext.Current //返回与

unicode string和ansi string的转换函数及获取程序运行路径的代码

#pragma once#include <string> namespace stds { class tool { public: std::string ws2s(const std::wstring& ws) { std::string curLocale = setlocale(LC_ALL, NULL); // curLocale = "C"; setlocale(LC_ALL, "chs"); const wchar_t* _Sou

linux关于readlink函数获取运行路径的小程序

摘自:http://blog.csdn.net/djzhao/article/details/8178375 linux关于readlink函数获取运行路径的小程序 相关函数: stat, lstat, symlink表头文件: #include <unistd.h>定义函数:int  readlink(const  char *path,  char *buf, size_t  bufsiz);函数说明:readlink()会将参数path的符号连接内容到参数buf所指的内存空间,返回的内容

android获取当前应用程序路径

// 获取当前程序路径 getApplicationContext().getFilesDir().getAbsolutePath(); // 获取该程序的安装包路径 String path=getApplicationContext().getPackageResourcePath(); // 获取程序默认数据库路径 getApplicationContext().getDatabasePath(s).getAbsolutePath();

[Windows]_[MacOSX]_[获取程序的执行文件所在路径(目录)]

场景: 1. 有时候有些辅助程序文件需要放在主程序文件同样的位置,便于管理和调用,这时候就需要通过主程序的路径来获取辅助程序所在位置. 2. 或者通过执行文件地址获取程序目录的安装地址. 方案: 1. 这里列出来省的大家去费神去找了. Windows实现: Unicode2Utf8实现搜博客里有- #include <Windows.h> #include <shlwapi.h> std::string GetExeDir() { static wchar_t szbuf[MAX_

C# 获取程序运行时路径

?  前言 开发中,很多时候都需要获取程序运行时路径,比如:反射.文件操作等..NET Framework 已经封装了这些功能,可以很方便的使用. 1.   可使用类 1.   System.AppDomain,程序集:mscorlib.dll. 2.   System.Environment,程序集:mscorlib.dll. 3.   System.IO.Directory,程序集:mscorlib.dll. 4.   System.Reflection.Assembly,程序集:mscor