c# 获得当前绝对路径的方法(超简单)
作者:jingxian 时间:2021-06-18 05:23:31
废话不多说,直接上代码
/// <summary>
/// 获得当前绝对路径
/// </summary>
/// <param name="strPath">指定的路径</param>
/// <returns>绝对路径</returns>
public static string GetMapPath(string strPath)
{
if (strPath.ToLower().StartsWith("http://"))
{
return strPath;
}
if (HttpContext.Current != null)
{
string path = HttpContext.Current.Server.MapPath("~/" + strPath);
return path;
}
else //非web程序引用
{
strPath = strPath.Replace("/", "\\");
if (strPath.StartsWith("\\"))
{
strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\');
}
return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath);
}
}
来源:http://www.cnblogs.com/highest/p/8301376.html
标签:c#,当前,绝对,路径
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
C语言实现双向链表
2023-05-30 08:02:24
![](https://img.aspxhome.com/file/2023/2/90192_0s.png)
IntelliJ IDEA像Eclipse一样打开多个项目的图文教程
2022-03-14 05:31:40
![](https://img.aspxhome.com/file/2023/3/78923_0s.jpg)
实例解析C++中类的成员函数指针
2022-12-24 06:10:04
推荐史上最全的IDEA好用插件
2023-02-22 21:35:04
![](https://img.aspxhome.com/file/2023/8/62378_0s.png)
Spring Bean后处理器详细介绍
2021-06-27 07:29:06
![](https://img.aspxhome.com/file/2023/4/61854_0s.png)
详解java中保持compareTo和equals同步
2023-07-20 12:20:53
Java环境配置原理全面解析
2023-11-23 07:56:48
![](https://img.aspxhome.com/file/2023/5/59925_0s.jpg)
C# 抓图服务的实现
2023-04-03 20:10:12
Jackson的用法实例分析
2021-11-13 09:13:40
Java实现人机猜拳游戏
2023-10-16 08:47:56
![](https://img.aspxhome.com/file/2023/5/80205_0s.png)
Java基于Socket实现HTTP下载客户端
2022-07-06 01:02:30
![](https://img.aspxhome.com/file/2023/7/114037_0s.png)
java使用dom4j解析xml配置文件实现抽象工厂反射示例
2022-11-10 15:45:38
C#实现的鼠标钩子
2021-10-29 22:48:29
![](https://img.aspxhome.com/file/2023/1/106461_0s.gif)
photoView实现图片多点触控效果
2023-06-21 20:16:03
![](https://img.aspxhome.com/file/2023/7/122057_0s.jpg)
java实现简易飞机大战
2022-08-27 12:36:07
![](https://img.aspxhome.com/file/2023/7/81227_0s.jpg)
C#时间格式转换为时间戳的方法步骤
2022-04-13 12:27:19
Spring MVC的优点与核心接口_动力节点Java学院整理
2023-11-28 05:43:36
![](https://img.aspxhome.com/file/2023/9/60529_0s.jpg)
举例讲解C#编程中对设计模式中的单例模式的运用
2023-04-28 19:34:10
![](https://img.aspxhome.com/file/2023/2/94632_0s.png)
springboot+thymeleaf 文件上传功能的实现代码
2023-11-25 05:08:59
![](https://img.aspxhome.com/file/2023/3/60053_0s.png)
SpringBoot配置Profile实现多环境支持
2023-07-29 21:53:20
![](https://img.aspxhome.com/file/2023/9/85419_0s.png)