Beispiel #1
0
        public static string SaveImage(this HttpContextBase ctx, HttpPostedFileBase file, bool createThumb = true, bool createMedium = false)
        {
            var config = ObjectFactory.GetInstance <IConfig>();

            var filename = ctx.GenerateUserFileName(file.FileName);

            var imagesPath = Path.Combine(ctx.Server.MapPath(config.GetSetting <string>("LargeImagePath")), filename);
            int size       = config.GetSetting <int>("ThumbSize");

            var image        = System.Drawing.Image.FromStream(file.InputStream);
            var resizedImage = ResizeImage(image, 800, 800);

            resizedImage.Save(imagesPath);

            if (createThumb)
            {
                var thumbPath = Path.Combine(ctx.Server.MapPath(config.GetSetting <string>("ThumbPath")), filename);
                var thumb     = image.GetThumbnailImage(size, size, null, IntPtr.Zero);
                thumb.Save(thumbPath, System.Drawing.Imaging.ImageFormat.Png);
            }

            if (createMedium)
            {
                var mediumPath  = Path.Combine(ctx.Server.MapPath(config.GetSetting <string>("MediumImagePath")), filename);
                var mediumImage = ResizeImage(image, 200, 200);
                mediumImage.Save(mediumPath);
            }

            return(filename);
        }
Beispiel #2
0
        public static string SaveAudio(this HttpContextBase ctx, HttpPostedFileBase file)
        {
            var config = ObjectFactory.GetInstance <IConfig>();

            var filename = ctx.GenerateUserFileName(file.FileName.Replace(" ", String.Empty));

            var audioPath = Path.Combine(ctx.Server.MapPath(config.GetSetting <string>("AudioPath")), filename);

            file.SaveAs(audioPath);

            return(filename);
        }