如何获得应用程序的物理路径
2013-08-04 16:41
369 查看
如果获得应用程序的物理路径(相对路径)呢?对此,我做了一下总结,代码如下:
1. 获得相对路径(winform适用)
2. 获得相对路径(web方面)
注意一下:方法2 中 必须添加 System.Web 引用!
1. 获得相对路径(winform适用)
/// <summary> /// 获得应用程序的物理路径(相对路径) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { string currentPath = System.IO.Directory.GetCurrentDirectory();//路径到\bin\Debug string path = currentPath.Split(new string[] { @"\bin" },StringSplitOptions.None)[0]; MessageBox.Show(path); }
2. 获得相对路径(web方面)
/// <summary> /// 获得应用程序的物理路径(相对路径) /// </summary> /// <returns></returns> public string GetCurrentPath() { string currentPath =System.Web.HttpContext.Current.Server.MapPath("~/bin"); return currentPath; }
注意一下:方法2 中 必须添加 System.Web 引用!
相关文章推荐
- 如何在 Java 代码中获得 WebRoot 的物理路径
- 4 如何获得控制台应用程序的路径
- C/MFC如何获得应用程序当前路径(整理)
- C/MFC如何获得应用程序当前路径(整理)
- 如何通过.Net Compact Framework来获得应用程序的当前路径
- C/MFC如何获得应用程序当前路径(整理)
- C/MFC如何获得应用程序当前路径(整理)
- 如何获得当前应用程序所在路径
- C/MFC如何获得应用程序当前路径(整理)
- C#如何获得服务器上的物理路径
- C/MFC如何获得应用程序当前路径(整理)
- [原创] 如何在 Java 代码中获得 WebRoot 的物理路径?(区分 Windows 和 Linux 的情况)
- 如何使Android应用程序获得root权限
- Android中如何修改系统信息(应用程序获得系统权限)
- 如何获取应用程序的路径
- c#中如何取得应用程序运行路径
- 如何取得.Net应用程序本身的路径
- 如何获得另一个应用程序窗口中的文本
- c#如何获得cpu,硬盘的物理序列号
- C#--如何获得文件保存路径的.txt文件