Ejemplo n.º 1
0
        private ViewModels.FotoVM MontarFoto(System.Web.HttpPostedFileBase file)
        {
            if (file.ContentLength > 1048576) //1MB
            {
                ModelState.AddModelError("", "Arquivo excedeu o limite permitido");
            }

            var      foto       = new ViewModels.FotoVM();
            FileInfo arqEnviado = null;

            arqEnviado = new FileInfo(file.FileName);

            if (arqEnviado != null)
            {
                foto.NomeArquivo     = arqEnviado.Name;
                foto.ExtensaoArquivo = arqEnviado.Extension;
                foto.TipoArquivo     = file.ContentType;
                using (var reader = new BinaryReader(file.InputStream))
                {
                    foto.Binario = reader.ReadBytes(file.ContentLength);
                }
            }

            return(foto);
        }
        private ViewModels.FotoVM MontarFoto(System.Web.HttpPostedFileBase file)
        {
            if (file.ContentLength > 1048576) //1MB
            {
                ModelState.AddModelError("", "Arquivo excedeu o limite permitido");
            }

            var foto = new ViewModels.FotoVM();
            FileInfo arqEnviado = null;
            arqEnviado = new FileInfo(file.FileName);

            if (arqEnviado != null)
            {
                foto.NomeArquivo = arqEnviado.Name;
                foto.ExtensaoArquivo = arqEnviado.Extension;
                foto.TipoArquivo = file.ContentType;
                using (var reader = new BinaryReader(file.InputStream))
                {
                    foto.Binario = reader.ReadBytes(file.ContentLength);
                }
            }

            return foto;
        }