Esempio n. 1
0
        /// <summary>
        /// Saves the provided image to the user's uploads folder
        /// </summary>
        /// <param name="_fileToSave">The _file to save.</param>
        /// <returns></returns>
        public ImageFileInfo SaveImage(HttpPostedFileBase _fileToSave)
        {
            string fullPath = Save(_fileToSave, UserImagesPath);

            var imgInfo = new ImageFileInfo();
            imgInfo.Filename = Path.GetFileName(fullPath);
            imgInfo.FullRelativePath = String.Format(UserImagesPath, this.UserName) + imgInfo.Filename;

            using (Image img = Image.FromFile(fullPath)) {
                imgInfo.Width = img.Width;
                imgInfo.Height = img.Height;
            }

            return imgInfo;
        }
Esempio n. 2
0
        /// <summary>
        /// Returns all images in the specified user's images directory
        /// </summary>
        /// <returns></returns>
        public List<ImageFileInfo> GetImages()
        {
            if (HttpContext.Current == null) {
                throw new InvalidOperationException("Must be withing a http request");
            }

            var server = HttpContext.Current.Server;
            string userName = this.UserName;
            string relativePath = String.Format(UserImagesPath, userName);
            string galleryPath = server.MapPath(relativePath);

            var lstFiles = new List<ImageFileInfo>();

            if (!Directory.Exists(galleryPath)) {
                Directory.CreateDirectory(galleryPath);
            }

            // enumerate all files in the user's directory in the server
            foreach (var file in Directory.GetFiles(galleryPath)) {
                string absolutePath = Path.Combine(galleryPath, file);
                var imgInfo = new ImageFileInfo();
                imgInfo.Filename = Path.GetFileName(file);
                imgInfo.FullRelativePath = relativePath + imgInfo.Filename;
                imgInfo.CreationDate = new FileInfo(file).CreationTime;

                using (Image img = Image.FromFile(absolutePath)) {
                    imgInfo.Width = img.Width;
                    imgInfo.Height = img.Height;
                }

                lstFiles.Add(imgInfo);
            }

            return lstFiles;
        }