protected override void OnSaving() { base.OnSaving(); if (FileData != null) { if (!FileData.IsEmpty) { string filePath = HttpContext.Current.Request.MapPath("~/FileData/" + FileData.FileName); Stream stream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write); FileData.SaveToStream(stream); var currentPicture = Image.FromStream(new System.IO.MemoryStream(FileData.Content)); var thumbImage = ScaleImage(currentPicture, 100); int fileExtPos = FileData.FileName.LastIndexOf("."); string thumbPath = ""; if (fileExtPos >= 0) { thumbPath = FileData.FileName.Substring(0, fileExtPos) + "_thumb" + Path.GetExtension(FileData.FileName); } thumbImage.Save(HttpContext.Current.Request.MapPath("~/FileData/" + thumbPath)); ImageUrl = "FileData/" + FileData.FileName; stream.Close(); FileData.Clear(); } } }
protected override void OnSaving() { base.OnSaving(); Routing = ValidateSystem.RejectMarks(Title.ToLower(), "-"); if (FileData != null) { if (!FileData.IsEmpty) { var request = System.Web.HttpContext.Current.Request; var requestUrl = request.Url; string filePath = request.MapPath("~/FileData/" + FileData.FileName); if (!System.IO.File.Exists(filePath)) { System.IO.Stream stream = new System.IO.FileStream(filePath, System.IO.FileMode.Create, System.IO.FileAccess.Write); FileData.SaveToStream(stream); var currentPicture = System.Drawing.Image.FromStream(new System.IO.MemoryStream(FileData.Content)); var thumbImage = ImageHelper.ScaleImage(currentPicture, 70); int fileExtPos = FileData.FileName.LastIndexOf("."); string thumbPath = ""; if (fileExtPos >= 0) { thumbPath = FileData.FileName.Substring(0, fileExtPos) + "_thumb" + System.IO.Path.GetExtension(FileData.FileName); } thumbImage.Save(request.MapPath("~/FileData/" + thumbPath)); stream.Close(); } PresentationImageUrl = requestUrl.Scheme + "://" + requestUrl.Host + ":" + requestUrl.Port + "/FileData/" + FileData.FileName; FileData.Clear(); } } }
private void spliteData() { FolderData.Clear(); FileData.Clear(); foreach (UserFileModel file in Data) { if (file.is_folder) { FolderData.Add(file); } else { FileData.Add(file); Debug.WriteLine("file", file.file_name); } } }
public static string SaveFileToServer(FileData FileData, string FolderPage) { if (FileData != null) { if (!FileData.IsEmpty) { var request = HttpContext.Current.Request; var requestUrl = request.Url; #region test address folderPage difficult null, if is null create folder string folderPath = request.MapPath("~/FileData/" + FolderPage + "/"); bool folderExists = Directory.Exists(folderPath); if (!folderExists) { Directory.CreateDirectory(folderPath); } #endregion string filePath = request.MapPath("~/FileData/" + FolderPage + "/" + FileData.FileName); if (!File.Exists(filePath)) { Stream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write); FileData.SaveToStream(stream); var currentPicture = System.Drawing.Image.FromStream(new System.IO.MemoryStream(FileData.Content)); var thumbImage = ImageHelper.ScaleImage(currentPicture, 100); int fileExtPos = FileData.FileName.LastIndexOf("."); string thumbPath = ""; if (fileExtPos >= 0) { thumbPath = FileData.FileName.Substring(0, fileExtPos) + "_thumb" + Path.GetExtension(FileData.FileName); } thumbImage.Save(request.MapPath("~/FileData/" + FolderPage + "/" + thumbPath)); stream.Close(); } string url = requestUrl.Scheme + "://" + requestUrl.Host + ":" + requestUrl.Port + Folder + "/FileData/" + FolderPage + "/" + FileData.FileName; FileData.Clear(); return(url); } } return(""); }
private static void ResetCoreData() { int oldRankMax = RankData.Count - 1; FileData.Clear(); // AddImage handles most of FileData RankData.Clear(); //? Loaded in when jsonWallpaperData is created ActiveImages.Clear(); //? Loaded in when jsonWallpaperData is created ImageFolders.Clear(); TaggingInfo = new TaggingInfo(); ImagesOfType.Clear(); ImagesOfTypeRankData.Clear(); ActiveImagesOfType.Clear(); WallpaperPathing.Reset(); InitializeImagesOfType(); // This is needed if loading otherwise images with invalid ranks will crash the program SetRankData(LargestMaxRank); }