public ActionResult UploadFile(string path) { try { if (string.IsNullOrWhiteSpace(path)) { throw new Exception("Path Empty"); } foreach (string upload in Request.Files) { HttpPostedFileBase file = Request.Files[upload]; if (file == null || file.ContentLength <= 0) { continue; } HttpPostedFileBase postedFile = Request.Files[upload]; byte[] buf = new byte[postedFile.InputStream.Length]; postedFile.InputStream.Read(buf, 0, (int)postedFile.InputStream.Length); MemoryStream ms = new MemoryStream(buf); storeCloudProvider.UploadFile(GetStoreCloud(), path, ms, postedFile.FileName); ViewBag.Files = storeCloudProvider.GetItemsByDirectory(GetStoreCloud(), path); ViewBag.path = path; } PageInfo.CreateAlert("Upload des fichiers terminé", 2); } catch (Exception ex) { PageInfo.CreateAlert(ex.Message, 4); } return(RedirectToAction("Index", new { path = path })); }
/// <summary> /// Validation l'edition /// </summary> /// <param name="sci">fichier</param> /// <returns></returns> public ActionResult SupprimerFichier(long idItem, string Path) { try { storeCloudProvider.DeleteFile(this.StoreCloudAssociation, idItem); PageInfo.CreateAlert("Suppression terminé", 2); } catch (Exception ex) { PageInfo.CreateAlert(ex.Message, 4); } return(RedirectToAction("Index", new { path = Path })); }
/// <summary> /// Validation l'edition /// </summary> /// <param name="sci">fichier</param> /// <returns></returns> public ActionResult ValiderEditerFichier(StoreCloudItemForm sci, string Path) { try { storeCloudProvider.EditFile(sci); PageInfo.CreateAlert("Modification terminé", 2); } catch (Exception ex) { PageInfo.CreateAlert(ex.Message, 4); //throw; } return(RedirectToAction("Index", new { path = Path })); }
public ActionResult UploadImage(string path) { try { if (string.IsNullOrWhiteSpace(path)) { throw new Exception("Path Empty"); } foreach (string upload in Request.Files) { HttpPostedFileBase file = Request.Files[upload]; if (file == null || file.ContentLength <= 0 || file.ContentLength > (1024 * 500)) { throw new Exception("Taille image dépasse 500 ko"); } HttpPostedFileBase postedFile = Request.Files[upload]; byte[] buf = new byte[postedFile.InputStream.Length]; postedFile.InputStream.Read(buf, 0, (int)postedFile.InputStream.Length); MemoryStream ms = new MemoryStream(buf); System.Drawing.Bitmap btp = new System.Drawing.Bitmap(ms); if (btp == null || btp.Size.Height < 400 || btp.Size.Width < 600) { throw new Exception("Dimension image inférieur à 400x600"); } Stream stream = new MemoryStream(); btp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); stream.Position = 0; StoreCloudItem img = storeCloudProvider.UploadFile(GetStoreCloud(), path, stream, postedFile.FileName); ViewBag.Files = storeCloudProvider.GetItemsByDirectory(GetStoreCloud(), path); ViewBag.path = path; } PageInfo.CreateAlert("Upload image terminé", 2); } catch (Exception ex) { PageInfo.CreateAlert(ex.Message, 4); } return(RedirectToAction("Index", new { path = path })); }