public static UploadPathInfo CreateUploadPath(string MainDirName, UploadPathType PathType, string UploadRootPath, string WebVirthPath) { return(PathUtils.CreateUploadPath(MainDirName, PathType, UploadRootPath, WebVirthPath)); }
//上传路径和目录 相关方法 /// <summary> /// 创建并获取上传要保存的路径(含物理路径和虚拟路径) /// </summary> /// <param name="SaveDirName">保存上传文件的主目录名,如为空,则默认为UploadFile</param> /// <param name="UploadRootPath">要保存上传文件所在根路径,如为空,则为当前应用物理路径</param> /// <param name="WebVirthPath">上传后访问的虚拟路径,如为空,则为相对路径</param> /// <param name="SiteUrl">如果是Web项目,则为该web项目的根路径</param> /// <returns></returns> public static UploadPathInfo CreateUploadPath(string MainDirName, UploadPathType PathType, string UploadRootPath, string WebVirthPath) { //TODO:物理路径 string SiteUrl = ""; //HttpContext page = HttpContext.Current; //if (page != null) //{ // try // { // SiteUrl = page.Server.MapPath("~/"); // } // catch { } //} MainDirName = RemovePathString(MainDirName); if (MainDirName.IsWhiteSpace()) { MainDirName = "Upload"; } string path = ""; if (PathType == UploadPathType.DaylyChildDir) { path = string.Format(@"{0}\{1:yyyyMMdd}", MainDirName, DateTime.Now); } else if (PathType == UploadPathType.MonthlyChildDir) { path = string.Format(@"{0}\{1:yyyyMM}", MainDirName, DateTime.Now); } else { path = MainDirName; } System.IO.Directory.GetCurrentDirectory(); string m_RelatPath, m_UploadPath;//物理路径和虚拟路径 m_RelatPath = path; m_UploadPath = GetMapPath(path, UploadRootPath, SiteUrl);//上传文件保存目录 //移除m_RelatPath前面的"/"字符 m_RelatPath = m_RelatPath.Replace(@"\", "/"); while (m_RelatPath.StartsWith(@"/") && m_RelatPath.Length > 1) { m_RelatPath = m_RelatPath.Substring(1); } if (m_RelatPath == @"/") { m_RelatPath = ""; } string wvp = WebVirthPath; if (!string.IsNullOrWhiteSpace(wvp)) { if (!wvp.EndsWith("/")) { wvp += "/"; } m_RelatPath = string.Format("{0}{1}", wvp, m_RelatPath); } if (!Directory.Exists(m_UploadPath)) //如果目录不存在,则建该目录 { Directory.CreateDirectory(m_UploadPath); } return(new UploadPathInfo() { PhysicalPath = m_UploadPath, VirthPath = m_RelatPath }); }