zoukankan      html  css  js  c++  java
  • 获得网站根目录路径

      //保存文件路径供DMT调用
             string CreatePath = "";
             public string  PathTy(int sealerID, int Type,string List)
             {
                 CreateFolder("temp");
                 string PathT =CreatePath+"\\"+ sealerID + "_" + Type + "_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

                 FileStream file = new FileStream(PathT, FileMode.Create, FileAccess.Write);
                     StreamWriter sw = new StreamWriter(file);
                     sw.Write(List);
                     sw.Close();

                     string path = GetRootURI() + "/" + "temp" + "/" + sealerID + "_" + Type + "_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
                     return path;
             }
          

    public string GetRootURI()
             {
                 string AppPath = "";
                 HttpContext HttpCurrent = HttpContext.Current;
                 HttpRequest Req;
                 if (HttpCurrent != null)
                 {
                     Req = HttpCurrent.Request;
                     string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
                     if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
                         //直接安装在   Web   站点  
                         AppPath = UrlAuthority;
                     else
                         //安装在虚拟子目录下  
                         AppPath = UrlAuthority + Req.ApplicationPath;
                 }
               //  CreateFolder("temp");
                 return AppPath;
             }
            //创建文件夹
             public string CreateFolder(string FolderPathName)
             {
                 if (FolderPathName.Trim().Length > 0)
                 {
                      CreatePath   = System.Web.HttpContext.Current.Server.MapPath( FolderPathName).ToString();
                         if (!Directory.Exists(CreatePath))
                         {
                             Directory.CreateDirectory(CreatePath);
                         }
                 }
                 return CreatePath;
             }

  • 相关阅读:
    Java学习笔记 -StringBuffer & StringBuilder
    Java学习笔记
    java学习笔记 -数组
    关于运放采集电路如何自动切换量程电路
    仪器仪表运放的放大倍数的一些问题
    二极管、三极管和mos管使用总结
    mos管缓启动和防反接电路原理
    关于产生负电源电路
    可靠性测试之画pcb
    AD软件pcb电路板各图层的理解
  • 原文地址:https://www.cnblogs.com/jimmychow/p/2307891.html
Copyright © 2011-2022 走看看