/// <summary> /// 获取文件 /// </summary> /// <param name="dir"></param> /// <returns></returns> private List <TreeNodeEntity> GetDirNode(string dir) { List <TreeNodeEntity> filesEntities = new List <TreeNodeEntity>(); string[] dirs = Directory.GetDirectories(dir); foreach (string InDir in dirs) { TreeNodeEntity dirNode = new TreeNodeEntity(); dirNode.Name = InDir.Substring(InDir.LastIndexOf("\\") + 1, InDir.Length - InDir.LastIndexOf("\\") - 1); dirNode.Open = false; dirNode.Children = GetDirNode(InDir); filesEntities.Add(dirNode); } string[] files = Directory.GetFiles(dir); foreach (string InFile in files) { TreeNodeEntity fileNode = new TreeNodeEntity(); CodeEntity ce = CodeOperation.GetCodeFromPath(dir.Replace( Server.MapPath(AppConfiger.GetProjectsDir(Server)), "") + "\\" + InFile.Substring(InFile.LastIndexOf("\\") + 1, InFile.Length - InFile.LastIndexOf("\\") - 1)); if (ce != null) { fileNode.Id = ce.Id; fileNode.Name = ce.Path.Substring(ce.Path.LastIndexOf("\\") + 1, ce.Path.Length - ce.Path.LastIndexOf("\\") - 1); fileNode.TargetName = "sourceFrame"; fileNode.UrlFormat = "/Viewer.aspx?id={0}"; filesEntities.Add(fileNode); } else { fileNode.Name = InFile.Substring(InFile.LastIndexOf("\\") + 1, InFile.Length - InFile.LastIndexOf("\\") - 1); filesEntities.Add(fileNode); } } return(filesEntities); }
protected void FixUrl(object sender, EventArgs e) { HyperLink hl = (HyperLink)sender; if (hl.NavigateUrl == "..") { string tempDir = Dir.Substring(0, Dir.LastIndexOf("\\")); if (tempDir == AppConfiger.GetProjectsDir(Server)) { hl.NavigateUrl = ""; } else { hl.NavigateUrl = Request.Url.AbsolutePath + "?dir=" + tempDir; } } else {/*如果是是文件夹*/ if (Directory.Exists(Server.MapPath(Dir + "\\" + hl.NavigateUrl))) { hl.NavigateUrl = Request.Url.AbsolutePath + "?dir=" + Dir + "\\" + hl.NavigateUrl + (Request.QueryString["projectname"] != null? "&projectname=" + Request.QueryString["projectname"].ToString():""); } else { /*如果是普通文件*/ dir = Request.QueryString["dir"].ToString(); dir = dir.Replace(AppConfiger.GetProjectsDir(Server), ""); CodeEntity ce = CodeOperation.GetCodeFromPath(dir + "\\" + hl.NavigateUrl); /*如果该文件已经登记在案*/ if (ce != null) { /*指向*/ hl.NavigateUrl = "/Viewer.aspx?id=" + ce.Id.ToString(); } else { hl.ForeColor = System.Drawing.Color.Gray; hl.NavigateUrl = ""; } } } /* * if (btn.Text == "..") * { * string tempDir = Dir.Substring(0, Dir.LastIndexOf("\\") + 1); * if (tempDir == Server.MapPath(AppConfiger.GetProjectsDir(Server))) * { * return; * } * else * { * this.Dir = tempDir; * } * } * else * { * this.Dir = dir + "\\" + btn.Text; * } */ }