public ActionResult ShowPhoto(Int32 id) { //This is my method for getting the image information // including the image byte array from the image column in // a database. byte[] fileData = null; try { using (var c = new ArtWorkDBEntities1()) { fileData = (from p in c.Artworks where p.ArtworkID == id select p.Image).FirstOrDefault(); //var fileExtension = (from p in c.Artworks // where p.ArtworkID == id // select p.FileExtension).FirstOrDefault(); } } catch (Exception) { throw; } //As you can see the use is stupid simple. Just get the image bytes and the // saved content type. See this is where the contentType comes in real handy. ImageResult result = new ImageResult(fileData, "jpg"); return(result); }
public FileContentResult GetImg(int id) { try { byte[] fileData = null; using (ArtworkViewModel vm = new ArtworkViewModel()) { using (var c = new ArtWorkDBEntities1()) { fileData = (from p in c.Artworks where p.ArtworkID == id select p.Image).FirstOrDefault(); var fileExtension = (from p in c.Artworks where p.ArtworkID == id select p.FileExtension).FirstOrDefault(); } FileContentResult varFile = new FileContentResult(fileData, "image/octet-stream"); return(varFile); // return new FileContentResult(fileData, "application/octet-stream", 1); } } catch (Exception) { throw; } }
protected void Page_Load(object sender, EventArgs e) { // var context = new ArtWorkDBEntities1(); if (!IsPostBack) { List <ViewModels.ArtworkViewModel> ArtworkVM = new List <ViewModels.ArtworkViewModel>(); //using (ViewModels.ArtworkViewModel ViewModle= new ViewModels.ArtworkViewModel ()) //{ // ArtworkVM = ViewModle.GetData(); // ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RPTReports/Report1.rdlc"); // ReportViewer1.LocalReport.DataSources.Clear(); // ReportDataSource rdc = new ReportDataSource("MyDataset", ArtworkVM); // ReportViewer1.LocalReport.DataSources.Add(rdc); // ReportViewer1.LocalReport.Refresh(); //} using (var context = new ArtWorkDBEntities1()) { } } }
public FileResult GetImageFromDataBase(int id) { byte[] fileData = null; try { using (var c = new ArtWorkDBEntities1()) { fileData = (from p in c.Artworks where p.ArtworkID == id select p.Image).FirstOrDefault(); //var fileExtension = (from p in c.Artworks // where p.ArtworkID == id // select p.FileExtension).FirstOrDefault(); } } catch (Exception) { throw; } return(File(fileData, "image/jpg"));; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List <ViewModels.ArtworkViewModel> ArtworkVM = new List <ViewModels.ArtworkViewModel>(); using (var context = new ArtWorkDBEntities1()) { var collection = (from p in context.Artworks join q in context.ArtTypes on p.ArtTypeID equals q.ArtTypeID select new { PurchasePrce = p.PurchasePrice , ArtType = q.ArtType1 } ).Sum(o => o.PurchasePrce); ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/RPTReports/Report1.rdlc"); ReportViewer1.LocalReport.DataSources.Clear(); ReportDataSource rdc = new ReportDataSource("SQlDataSource1", collection); ReportViewer1.LocalReport.DataSources.Add(rdc); ReportViewer1.LocalReport.Refresh(); } } }
public PhotoViewImage GetByID(int id) { var q = new PhotoViewImage(); byte[] fileData = null; try { using (var c = new ArtWorkDBEntities1()) { fileData = (from p in c.Artworks where p.ArtworkID == id select p.Image).FirstOrDefault(); //var fileExtension = (from p in c.Artworks // where p.ArtworkID == id // select p.FileExtension).FirstOrDefault(); q.actualimage = fileData; } } catch (Exception) { throw; } return(q); }