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;
                    }
                }
            }
  • 相关阅读:
    Scratch编程:初识Scratch及编程工具安装(一)
    关于少儿编程教育,这三大事项必须提前了解
    Scratch 少儿编程之旅(四)— Scratch入门动画《小猫捉蝴蝶》(中)
    操作系统:概述
    剑指offer:斐波那契数列
    剑指offer:旋转数组的最小数字
    剑指offer:用两个栈实现一个队列
    剑指offer:重建二叉树
    剑指offer:从尾到头打印链表
    剑指offer:替换空格
  • 原文地址:https://www.cnblogs.com/Aricc/p/1358201.html
Copyright © 2011-2022 走看看