Esempio n. 1
0
        public ActionResult fileupload()
        {
            HttpPostedFileBase file = HttpContext.Request.Files[0];

            using (BinaryReader reader = new BinaryReader(file.InputStream))
            {
                byte[] value = reader.ReadBytes((Int32)file.ContentLength);
                if (Session["value"] == null)
                {
                    Session["value"] = value;
                }
                else
                {
                    Session["value"] = UtilityManager.ByteBirlestir((byte[])Session["value"], value);
                }
                if (10000 > file.ContentLength)
                {
                    context.Dosya.Add(new Dosya
                    {
                        Deger         = (byte[])Session["value"],
                        DosyaAdi      = file.FileName,
                        DosyaBoyutu   = ((byte[])Session["value"]).Length.ToString(),
                        DosyaTipi     = file.ContentType,
                        Ikon          = UtilityManager.SetIcon(file.ContentType),
                        BoyutKisaltma = UtilityManager.ByteToString(((byte[])Session["value"]).Length),
                        Renk          = UtilityManager.SetClass(file.ContentType),
                        KayitTarihi   = DateTime.Now,
                    });
                    context.SaveChanges();
                    Session["value"] = null;
                }
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult FileUpload()
        {
            HttpPostedFileBase file = HttpContext.Request.Files[0];

            if (file != null)
            {
                using (BinaryReader reader = new BinaryReader(file.InputStream))
                {
                    byte[] value = reader.ReadBytes(file.ContentLength);
                    if (Session["value"] == null)
                    {
                        Session["value"] = value;
                    }
                    else
                    {
                        Session["value"] = UtilityManager.ByteBirlestir((byte[])Session["value"], value);
                    }


                    if (10000 > file.ContentLength)
                    {
                        _context.Dosya.Add(new Dosya()
                        {
                            Deger         = (byte[])Session["value"],
                            DosyaAdi      = file.FileName,
                            DosyaBoyutu   = ((byte[])Session["value"]).Length.ToString(),
                            DosyaTipi     = file.ContentType,
                            Ikon          = UtilityManager.SetIcon(file.ContentType),
                            BoyutKisaltma = UtilityManager.BytesToString(((byte[])Session["value"]).Length),
                            Renk          = UtilityManager.SetClass(file.ContentType),
                            KayitTarihi   = DateTime.Now
                        });
                        try
                        {
                            _context.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.Message);
                        }
                        Session["value"] = null;
                    }
                }
            }
            return(Json(""));
        }
Esempio n. 3
0
        public ActionResult FileUpload()
        {
            //Upload'dan gelen dtanin tipi HttpPostedFileBase olacak.
            HttpPostedFileBase file = HttpContext.Request.Files[0];

            //10KB şeklinde gelen verileri birleştirip veritabanına byte tipinde yazacağız
            using (BinaryReader reader = new BinaryReader(file.InputStream))
            {
                byte[] value = reader.ReadBytes((Int32)file.ContentLength);
                if (Session["value"] == null)
                {
                    Session["value"] = value;
                }
                else
                {
                    Session["value"] = UtilityManager.ByteBirlestir((byte[])Session["value"], value);
                }
                if (10000 > file.ContentLength)
                {
                    _galerYonetimContext.Dosya.Add(new Dosya
                    {
                        Deger         = (byte[])Session["value"],
                        DosyaAdi      = file.FileName,
                        DosyaBoyutu   = ((byte[])Session["value"]).Length,
                        DosyaTipi     = file.ContentType,
                        Ikon          = UtilityManager.setIcon(file.ContentType),
                        BoyutKisaltma = UtilityManager.BytesToString(((byte[])Session["value"]).Length),
                        KayitTarihi   = DateTime.Now
                    });
                    _galerYonetimContext.SaveChanges();
                    Session["value"] = null;
                }
            }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        public ActionResult UploadData()
        {
            HttpPostedFileBase file = HttpContext.Request.Files[0];

            //disposable
            using (BinaryReader reader = new BinaryReader(file.InputStream))
            {
                byte[] deger = reader.ReadBytes(file.ContentLength);

                if (Session["Alafortanfoni"] == null)
                {
                    Session["Alafortanfoni"] = deger;
                }
                else
                {
                    Session["Alafortanfoni"] = UtilityManager.ByteBirlestir((byte[])Session["Alafortanfoni"], deger);
                }
                if (file.ContentLength < 10000)
                {
                    _db.Dosyalar.Add(new Dosya
                    {
                        Deger         = (byte[])Session["Alafortanfoni"],
                        DosyaAdi      = file.FileName,
                        DosyaBoyutu   = ((byte[])Session["Alafortanfoni"]).Length,
                        DosyaTipi     = file.ContentType,
                        IkonBootstrap = UtilityManager.setIcon(file.ContentType),
                        IkonResim     = UtilityManager.setImage(file.ContentType),
                        KayitTarihi   = DateTime.Now,
                    });
                    _db.SaveChanges();

                    Session.Remove("Alafortanfoni");
                }
            }
            return(Json("", JsonRequestBehavior.AllowGet));
        }