public virtual ActionResult Create(string target, FileManagerEntry entry) { FileManagerEntry newEntry; if (!Authorize(NormalizePath(target))) { throw new HttpException(403, "Forbidden"); } if (String.IsNullOrEmpty(entry.Path)) { newEntry = CreateNewFolder(target, entry); } else { newEntry = CopyEntry(target, entry); } return(Json(new { name = newEntry.Name, size = newEntry.Size, path = ToVirtual(newEntry.Path), extension = newEntry.Extension, isDirectory = newEntry.IsDirectory, hasDirectories = newEntry.HasDirectories, created = newEntry.Created, createdUtc = newEntry.CreatedUtc, modified = newEntry.Modified, modifiedUtc = newEntry.ModifiedUtc })); }
public virtual ActionResult Update(string target, FileManagerEntry entry) { FileManagerEntry newEntry; if (!Authorize(NormalizePath(entry.Path)) && !Authorize(NormalizePath(target))) { throw new HttpException(403, "Forbidden"); } newEntry = RenameEntry(entry); return(Json(new { name = newEntry.Name, size = newEntry.Size, path = ToVirtual(newEntry.Path), extension = newEntry.Extension, isDirectory = newEntry.IsDirectory, hasDirectories = newEntry.HasDirectories, created = newEntry.Created, createdUtc = newEntry.CreatedUtc, modified = newEntry.Modified, modifiedUtc = newEntry.ModifiedUtc })); }
protected virtual string EnsureUniqueName(string target, FileManagerEntry entry) { var tempName = entry.Name + entry.Extension; int sequence = 0; var physicalTarget = Path.Combine(NormalizePath(target), tempName); if (!Authorize(NormalizePath(physicalTarget))) { throw new Exception("Forbidden"); } if (entry.IsDirectory) { while (Directory.Exists(physicalTarget)) { tempName = entry.Name + String.Format("({0})", ++sequence); physicalTarget = Path.Combine(NormalizePath(target), tempName); } } else { while (System.IO.File.Exists(physicalTarget)) { tempName = entry.Name + String.Format("({0})", ++sequence) + entry.Extension; physicalTarget = Path.Combine(NormalizePath(target), tempName); } } return(physicalTarget); }
private string EnsureUniqueName(string target, FileManagerEntry entry) { var tempName = entry.Name + entry.Extension; int sequence = 0; var physicalTarget = Path.Combine(Server.MapPath(target), tempName); if (entry.IsDirectory) { while (Directory.Exists(physicalTarget)) { tempName = entry.Name + String.Format("({0})", ++sequence); physicalTarget = Path.Combine(Server.MapPath(target), tempName); } } else { while (System.IO.File.Exists(physicalTarget)) { tempName = entry.Name + String.Format("({0})", ++sequence) + entry.Extension; physicalTarget = Path.Combine(Server.MapPath(target), tempName); } } return(physicalTarget); }
private string EnsureUniqueName(string target, FileManagerEntry entry) { var tempName = entry.Name + entry.Extension; int sequence = 0; var physicalTarget = NormalizePath(Path.Combine(target, tempName)); if (!Authorize(physicalTarget)) { throw new HttpException(403, "Forbidden"); } physicalTarget = Server.MapPath(physicalTarget); if (entry.IsDirectory) { while (Directory.Exists(physicalTarget)) { tempName = entry.Name + String.Format("({0})", ++sequence); physicalTarget = Path.Combine(Server.MapPath(target), tempName); } } else { while (System.IO.File.Exists(physicalTarget)) { tempName = entry.Name + String.Format("({0})", ++sequence) + entry.Extension; physicalTarget = Path.Combine(Server.MapPath(target), tempName); } } return(physicalTarget); }
protected virtual FileManagerEntry CreateNewFolder(string target, FileManagerEntry entry) { FileManagerEntry newEntry; var path = NormalizePath(target); string physicalPath = EnsureUniqueName(path, entry); Directory.CreateDirectory(physicalPath); newEntry = directoryBrowser.GetDirectory(physicalPath); return(newEntry); }
/// <summary> /// Updates an entry with a given entry. /// </summary> /// <param name="path">The path to the parent folder in which the folder should be created.</param> /// <param name="entry">The entry.</param> /// <returns>An empty <see cref="ContentResult"/>.</returns> /// <exception cref="HttpException">Forbidden</exception> public virtual ActionResult Update(string target, FileManagerEntry entry) { FileManagerEntry newEntry; if (!Authorize(NormalizePath(entry.Path)) && !Authorize(NormalizePath(target))) { throw new Exception("Forbidden"); } newEntry = RenameEntry(entry); return(Json(VirtualizePath(newEntry))); }
public virtual ActionResult Create(string target, FileManagerEntry entry) { return(Json(new { FolderId = 110, Name = "NewFolder", IsDirectory = true, HasDirectories = false, Path = "NewFolder", Extension = "", Size = 0, CreatedUtc = new DateTime(), })); }
/// <summary> /// Updates an entry with a given entry. /// </summary> /// <param name="path">The path to the parent folder in which the folder should be created.</param> /// <param name="entry">The entry.</param> /// <returns>An empty <see cref="ContentResult"/>.</returns> /// <exception cref="HttpException">Forbidden</exception> public virtual ActionResult Update(string target, FileManagerEntry entry) { FileManagerEntry newEntry; if (!Authorize(NormalizePath(entry.Path)) && !Authorize(NormalizePath(target))) { throw new Exception("Forbidden"); } newEntry = RenameEntry(entry); return(Json(VirtualizePath(newEntry), new System.Text.Json.JsonSerializerOptions() { PropertyNameCaseInsensitive = false })); }
public virtual ActionResult Destroy(FileManagerEntry entry) { var path = NormalizePath(entry.Path); if (!string.IsNullOrEmpty(path)) { if (entry.IsDirectory) { DeleteDirectory(path); } else { DeleteFile(path); } return(Json(new object[0])); } throw new HttpException(404, "File Not Found"); }
private FileManagerEntry RenameEntry(FileManagerEntry entry) { var path = NormalizePath(entry.Path); var physicalPath = Server.MapPath(path); var physicalTarget = EnsureUniqueName(Path.GetDirectoryName(path), entry); FileManagerEntry newEntry; if (entry.IsDirectory) { Directory.Move(physicalPath, physicalTarget); newEntry = directoryProvider.GetDirectory(physicalTarget); } else { var file = new FileInfo(physicalPath); System.IO.File.Move(file.FullName, physicalTarget); newEntry = directoryProvider.GetFile(physicalTarget); } return(newEntry); }
private FileManagerEntry CopyEntry(string target, FileManagerEntry entry) { var path = NormalizePath(entry.Path); var physicalPath = Server.MapPath(path); var physicalTarget = EnsureUniqueName(NormalizePath(target), entry); FileManagerEntry newEntry; if (entry.IsDirectory) { CopyDirectory(new DirectoryInfo(physicalPath), Directory.CreateDirectory(physicalTarget)); newEntry = directoryProvider.GetDirectory(physicalTarget); } else { System.IO.File.Copy(physicalPath, physicalTarget); newEntry = directoryProvider.GetFile(physicalTarget); } return(newEntry); }
protected virtual FileManagerEntry RenameEntry(FileManagerEntry entry) { var path = NormalizePath(entry.Path); var physicalPath = path; var physicalTarget = EnsureUniqueName(Path.GetDirectoryName(path), entry); FileManagerEntry newEntry; if (entry.IsDirectory) { Directory.Move(physicalPath, physicalTarget); newEntry = directoryBrowser.GetDirectory(physicalTarget); } else { var file = new FileInfo(physicalPath); System.IO.File.Move(file.FullName, physicalTarget); newEntry = directoryBrowser.GetFile(physicalTarget); } return(newEntry); }
public virtual ActionResult Create(string target, FileManagerEntry entry) { FileManagerEntry newEntry; if (!Authorize(NormalizePath(target))) { throw new Exception("Forbidden"); } if (String.IsNullOrEmpty(entry.Path)) { newEntry = CreateNewFolder(target, entry); } else { newEntry = CopyEntry(target, entry); } return(Json(VirtualizePath(newEntry))); }
protected virtual FileManagerEntry CopyEntry(string target, FileManagerEntry entry) { var path = NormalizePath(entry.Path); var physicalPath = path; var physicalTarget = EnsureUniqueName(NormalizePath(target), entry); FileManagerEntry newEntry; if (entry.IsDirectory) { CopyDirectory(new DirectoryInfo(physicalPath), Directory.CreateDirectory(physicalTarget)); newEntry = directoryBrowser.GetDirectory(physicalTarget); } else { //System.IO.File.Copy(physicalPath, physicalTarget); System.IO.File.Copy(physicalPath, physicalTarget, false); newEntry = directoryBrowser.GetFile(physicalTarget); } return(newEntry); }
public virtual ActionResult Create(string target, FileManagerEntry entry) { FileManagerEntry newEntry; if (!Authorize(NormalizePath(target))) { throw new Exception("Forbidden"); } if (String.IsNullOrEmpty(entry.Path)) { newEntry = CreateNewFolder(target, entry); } else { newEntry = CopyEntry(target, entry); } return(Json(VirtualizePath(newEntry), new System.Text.Json.JsonSerializerOptions() { PropertyNameCaseInsensitive = false })); }
public virtual ActionResult Destroy(FileManagerEntry entry) { var path = NormalizePath(entry.Path); if (!string.IsNullOrEmpty(path)) { if (entry.IsDirectory) { DeleteDirectory(path); } else { DeleteFile(path); } return(Json(new object[0], new System.Text.Json.JsonSerializerOptions() { PropertyNameCaseInsensitive = false })); } throw new Exception("File Not Found"); }
protected virtual FileManagerEntry VirtualizePath(FileManagerEntry entry) { entry.Path = entry.Path.Replace(Path.Combine(this.HostingEnvironment.WebRootPath, ContentPath), "").Replace(@"\", "/").TrimStart('/'); return(entry); }