public ActionResult FileUpload(FilePostData data) { var repo = _GetRepo(data); if (repo == null) { return(new HttpNotFoundResult()); } try { // TODO: in the future manage issues with versions in this repo var fullPath = repo.GetFullPath(data.Path, data.Name); if (System.IO.File.Exists(fullPath) && !data.Confirm) { return(Json("conflict")); } else { using (var stream = System.IO.File.OpenWrite(fullPath)) { data.File.InputStream.CopyTo(stream); } return(Json("success")); } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult FileDelete(FilePostData data) { var repo = _GetRepo(data); if (repo == null) { return(new HttpNotFoundResult()); } try { // TODO: in the future manage issues with versions in this repo var path = repo.GetFullPath(data.Path, data.Name); var isFolder = false; if (!System.IO.File.Exists(path)) { if (!System.IO.Directory.Exists(path)) { return(new HttpNotFoundResult()); } isFolder = true; } if (isFolder) { System.IO.Directory.Delete(path, true); } else { System.IO.File.Delete(path); } return(Json("success")); } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }
public ActionResult FileCopy(FilePostData data) { var repo = _GetRepo(data); if (repo == null) { return(new HttpNotFoundResult()); } try { // TODO: in the future manage issues with versions in this repo var oldPath = repo.GetFullPath(data.Path, data.Name); var newBasePath = repo.GetFullPath(data.NewPath); var newFullPath = repo.GetFullPath(data.NewPath, data.NewName); var isFolder = false; if (!System.IO.File.Exists(oldPath)) { if (!System.IO.Directory.Exists(oldPath)) { return(new HttpNotFoundResult()); } isFolder = true; } if (isFolder) { if (!System.IO.Directory.Exists(newBasePath)) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Destination path does not exist")); } else { var oldFolder = System.IO.Directory.CreateDirectory(oldPath); if (System.IO.Directory.Exists(newFullPath) && !data.Confirm) { return(Json("conflict")); } else { oldFolder.CopyTo(newFullPath); return(Json("success")); } } } else { if (System.IO.File.Exists(newFullPath) && !data.Confirm) { return(Json("conflict")); } else { System.IO.File.Copy(oldPath, newFullPath); return(Json("success")); } } } catch (Exception ex) { Elmah.ErrorSignal.FromCurrentContext().Raise(ex); return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message)); } }