Конвертировать файл в байт и прочитать - PullRequest
0 голосов
/ 07 октября 2018

Я хочу преобразовать файл в байт, чем прочитать его.мои коды там.

        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"] = App_Classes.StaticFunctions.byteBirlestir((byte[])Session["value"], value);
            if (10000 > file.ContentLength)
            {
                Session["value"] = App_Classes.StaticFunctions.byteBirlestir((byte[])Session["value"], value);
                Ctx.Dosya.Add(new Dosya
                {
                    Deger = (byte[])Session["value"],
                    DosyaAdi = file.FileName,
                    DosyaBoyutu = ((byte[])Session["value"]).Length.ToString(),
                    DosyaTipi = file.ContentType,
                    KayitTarihi = DateTime.Now,
                });
                Ctx.SaveChanges();
                Session["value"] = null;
            }
        }
        return Json("", JsonRequestBehavior.AllowGet);
    }

И моя функция чтения есть,

     public FileContentResult fileView()
    {
        var list = Ctx.Dosya.ToList();
        return new FileContentResult(list[0].Deger, list[0].DosyaTipi);
    }

когда я его построил, мой файл поврежден.

вот так http://prntscr.com/l34j0e

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...