• 获得网站根目录路径


      //保存文件路径供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;
             }

  • 相关阅读:
    Python变量小秘密
    Python编解码问题与文本文件处理
    Java持久层框架Mybatis入门
    teprunner重磅更新Git打通PyCharm与测试平台
    JMeter定时器设置延迟与同步
    Docker开启安全的TLS远程连接
    消息队列之如何保证消息的幂等性
    消息队列之如何保证消息的可靠传输
    spring技术内幕学习笔记01
    linux操作指南-04
  • 原文地址:https://www.cnblogs.com/jimmychow/p/2307891.html
Copyright © 2020-2023  润新知