I have a project, built with Visual Web Developer 2008. I want to be able to extract (with C#), the current folder the project is in now. Until now I had to hard code the true path.
This project is hosted on my computer.
For example, the path I would like to generate:
C:\Users\Guy\Desktop\Project
Thanks! Guy
基础装配解析器目录:
AppDomain.CurrentDomain.BaseDirectory;
最安全的方式:
string temp = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
If you are only reading, then
Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
works. But if you want to write to, then you'd have to go with:
AppDomain.CurrentDomain.BaseDirectory;
Or you will get an
{"URI formats are not supported."}
exception because your path is
file:\\C:\\Projects\
instead of
C:\\Projects
要将页面(或虚拟目录)映射到文件系统位置(在运行时),您可以使用Server.MapPath("/")
采用:
Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.