private void SetFileList(DirectoryInfo di) { var files = di.GetFiles(); var the_Files = new List <FileInfo>(); foreach (FileInfo fi in files) { if (FileFilters.IsValidFile(fi.Name)) { the_Files.Add(fi); } } if (the_Files.Count > 0) { the_Files.Sort(delegate(FileInfo f1, FileInfo f2) { return(Comparer <string> .Default.Compare(f1.Name, f2.Name)); }); int half = the_Files.Count / 2 + the_Files.Count % 2; var left = new List <AFile>(); var right = new List <AFile>(); for (int i = 0; i < the_Files.Count; i++) { AFile af = new AFile(); af.Name = the_Files[i].Name; af.Path = Request.QueryString["path"] ?? ""; af.OnClick = string.IsNullOrEmpty(OnClientFileClickedFunction) ? "" : "return select('" + GetJavaScriptUrl(the_Files[i].FullName) + "');"; if (i + 1 <= half) { left.Add(af); } else { right.Add(af); } } LeftFiles.DataSource = left; LeftFiles.DataBind(); RightFiles.DataSource = right; RightFiles.DataBind(); } }
protected void SaveFile_Click(object sender, EventArgs e) { FileInfo fi = GetFile(); if (FileFilters.IsEditable(fi.Name) && FileFilters.IsValidFile(fi.Name)) { try { bool isversioned = FileFilters.IsVersionable(fi.Name); if (isversioned && VersionStore.CurrentVersion(fi) == 0) { VersionStore.VersionFile(fi); } using (StreamWriter sw = new StreamWriter(fi.FullName, false)) { sw.Write(EditBox.Text); sw.Close(); } if (isversioned) { fi = GetFile(); VersionStore.VersionFile(fi); version = VersionStore.CurrentVersion(fi).ToString(); SetVersioning(fi.FullName); } EditMessage.Text = "<strong>" + fi.Name + "</strong> was successfully updated."; EditMessage.Type = StatusType.Success; } catch (Exception ex) { EditMessage.Text = "Your file could not be updated. \n\n Reason: " + ex.Message; EditMessage.Type = StatusType.Error; } } }
protected void Page_Load(object sender, EventArgs e) { LiHyperLink.SetNameToCompare(Context, "settings"); DeleteButton.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this file? This action cannot be undone!');"); string rootPath = Server.MapPath("~/"); string path = Request.QueryString["path"] ?? ""; if (!path.ToLower().StartsWith(basicFilesMediaPath) && !GraffitiUsers.IsAdmin(GraffitiUsers.Current)) { Response.Redirect(Request.Url.AbsolutePath + "?path=" + basicFilesMediaPath, true); } path = Path.Combine(rootPath, Util.NormalizePath(path)); string fileName = Request.QueryString["f"]; DirectoryInfo di = new DirectoryInfo(path); if (!di.FullName.ToLower().StartsWith(rootPath.ToLower())) { Log.Error("FileBrowser", "A request was made to an invalid directory {0}. If this persists, you should contact your ISP", di.FullName); throw new Exception("Bad Path"); } SetBreadCrumbs(fileName); SetFolders(di, rootPath); if (string.IsNullOrEmpty(fileName)) { FileViews.SetActiveView(FileLists); SetFileList(di); } else { FileInfo fi = new FileInfo(Path.Combine(path, fileName)); if (!fi.Exists) { Log.Warn("FileBrowser", "A requested file {0} does not exist", fi.FullName); throw new Exception("File does not exist"); } if (!FileFilters.IsValidFile(fi.Name)) { Log.Error("FileBrowser", "A forbidden file {0} was requested by the FileBrowser. Access to view/edit this file has been denied.", fi.FullName); throw new Exception("File does not exist"); } if (Request.QueryString["edit"] != "true") { SetFileDetails(fi); } else { SetFileEdit(fi); } } }