Ejemplo n.º 1
0
        public ActionResult SaveFile(IEnumerable <HttpPostedFileBase> Files)
        {
            var fh = new FileUploadHandler(Server, Session, false, "~/SimpleCMS/Data/Images");

            if (fh.Save(Files))
            {
                byte[]   data     = null;
                FileInfo fileInfo = null;
                foreach (var item in Files)
                {
                    ReadFileData(new FileUploadInfo()
                    {
                        FileName = Path.GetFileName(item.FileName), Extension = Path.GetExtension(item.FileName), UID = null
                    }, out data, out fileInfo);
                    if (data != null && fileInfo != null)
                    {
                        var file = new SimpleCMS.Models.File()
                        {
                            Name        = fileInfo.Name,
                            ContentType = MimeMapping.GetMimeMapping(fileInfo.FullName),
                            Length      = fileInfo.Length,
                            Data        = data,
                            ChangeEvent = CreateChangeEvent()
                        };
                        db.Files.Add(file);
                    }
                }
                db.SaveChanges();
                return(Content(""));
            }
            return(Content("Error"));
        }
Ejemplo n.º 2
0
        public ActionResult SaveFile(IEnumerable <HttpPostedFileBase> Files)
        {
            var fh = new FileUploadHandler(Server, Session, false, "~/Views/Shared/BlogViewTemplates");

            if (fh.Save(Files))
            {
                return(Content(""));
            }
            return(Content("Error"));
        }
Ejemplo n.º 3
0
        internal List <ImageInfo> SaveImages(IEnumerable <HttpPostedFileBase> Files)
        {
            var fh = new FileUploadHandler(Server, Session, false, GetImagesPath());

            if (fh.Save(Files))
            {
                return(SaveImages());
            }
            return(null);
        }
Ejemplo n.º 4
0
        public ActionResult SaveFile(IEnumerable <HttpPostedFileBase> Files)
        {
            var fh = new FileUploadHandler(Server, Session, false, "~/SimpleCMS/Data/Plugins");

            if (fh.Save(Files))
            {
                return(Content(""));
            }
            return(Content("Error"));
        }
Ejemplo n.º 5
0
        public ActionResult SaveFile(IEnumerable <HttpPostedFileBase> Files)
        {
            var fh = new FileUploadHandler(Server, Session, false, "~/SimpleCMS/Data/Images");

            if (fh.Save(Files))
            {
                //var files = AddFiles(vmObj.Files);
                foreach (var fileInfo in FileUploadHandler.UploadedFiles)
                {
                    var file = new SimpleCMS.Models.File()
                    {
                        Name        = fileInfo.Name,
                        Length      = fileInfo.Length,
                        ContentType = MimeMapping.GetMimeMapping(fileInfo.FullName),
                        Data        = System.IO.File.ReadAllBytes(Server.MapPath(Path.Combine("~/SimpleCMS/Data/Images", fileInfo.Name))),
                        ChangeEvent = CreateChangeEvent()
                    };
                    var dbObj = new ImageInfo()
                    {
                        Width       = -1,
                        Height      = -1,
                        Description = string.Empty,
                        File        = file,
                        ChangeEvent = CreateChangeEvent()
                    };
                    using (FileStream fs = new FileStream(Server.MapPath(Path.Combine("~/SimpleCMS/Data/Images", file.Name)), FileMode.Open, FileAccess.Read))
                    {
                        using (Image img = Image.FromStream(stream: fs,
                                                            useEmbeddedColorManagement: false,
                                                            validateImageData: false))
                        {
                            float width  = img.PhysicalDimension.Width;
                            float height = img.PhysicalDimension.Height;
                            //float hresolution = img.HorizontalResolution;
                            //float vresolution = img.VerticalResolution;
                            dbObj.Width  = (int)width;
                            dbObj.Height = (int)height;
                        }
                        fs.Close();
                    }
                    db.Files.Add(file);
                    db.Images.Add(dbObj);
                    db.SaveChanges();
                }
                return(Content(""));
            }
            return(Content("Error"));
        }