Csharp/C#教程:c# 获得当前绝对路径的方法(超简单)分享

废话不多说,直接上代码

///<summary> ///获得当前绝对路径 ///</summary> ///<paramname="strPath">指定的路径</param> ///<returns>绝对路径</returns> publicstaticstringGetMapPath(stringstrPath) { if(strPath.ToLower().StartsWith("https://")) { returnstrPath; } if(HttpContext.Current!=null) { stringpath=HttpContext.Current.Server.MapPath("~/"+strPath); returnpath; } else//非web程序引用 { strPath=strPath.Replace("/","\"); if(strPath.StartsWith("\")) { strPath=strPath.Substring(strPath.IndexOf('\',1)).TrimStart('\'); } returnSystem.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory,strPath); } }

上述就是C#学习教程:c# 获得当前绝对路径的方法(超简单)分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/908133.html

(0)
上一篇 2021年10月25日
下一篇 2021年10月25日

精彩推荐