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;
             }

  • 相关阅读:
    ubuntu server编译安装nginx
    XPath具体解释
    windows下安装,配置gcc编译器
    给字符数组赋值的方法
    开机黑屏 仅仅显示鼠标 电脑黑屏 仅仅有鼠标 移动 [已成功解决]
    MiinCMP1.0 SAE 新浪云版公布, 开源企业站点系统
    Mac下cocos2dx-3.0打包Android时,提示"SimpleAudioEngine.h"not found的解决方法
    GG同步到sqlserver报错一例 Invalid date format
    分布式文件系统
    动画clip仅仅读的解决的方法,以及动画关键帧回调的办法
  • 原文地址:https://www.cnblogs.com/jimmychow/p/2307891.html
Copyright © 2011-2022 走看看