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));
        }