zoukankan      html  css  js  c++  java
  • WebForm和WinForm通用的取当前根目录的方法

    这里需要注意的就是,如果是在Global.asax中添加计时器,在计时器的处理程序中就不能用Server.MapPath获得网站根目录了。

            public static string BasePath
            {
                
    get
                {
                    System.Diagnostics.Process p 
    = System.Diagnostics.Process.GetCurrentProcess();
                    
    //WebDev.WebServer      visual studio web server
                    
    //xxx.vhost             Winform
                    
    //w3wp                  IIS7
                    
    //aspnet_wp             IIS6
                    string processName = p.ProcessName.ToLower();
                    
    if (processName == "aspnet_wp" || processName == "w3wp" || processName == "webdev.webserver")
                    {
                        
    if (System.Web.HttpContext.Current != null)
                            
    return System.Web.HttpContext.Current.Server.MapPath("~/").TrimEnd(new char[] { '\\' });
                        
    else //当控件在定时器的触发程序中使用时就为空
                        {
                            
    return System.AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] { '\\' });
                        }
                    }
                    
    else
                    {
                        
    return System.Windows.Forms.Application.StartupPath;
                    }
                }
            }
  • 相关阅读:
    docker固定IP地址重启不变
    关于 CentOS 7 里面 普通用户 Ulimit max user processes 值的问题
    CentOS tengine mysql 5.7 php 5.6
    strace 分析 跟踪 进程错误
    WPF中的字体改善
    C#数据类型-string
    WPF中的文字修饰
    Winform与WPF对话框(MessageBox, Dialog)之比较
    WPF中将四个数字字符串值(比如:"10,10,300,300")转为Rect
    WPF中嵌入Flash(ActiveX)
  • 原文地址:https://www.cnblogs.com/Aricc/p/1358201.html
Copyright © 2011-2022 走看看