Posts
Showing posts from 2019
C# MVC Load Image Asychrnously
- Get link
- X
- Other Apps
By
Safeer
-
Razor HTML Code <img width="130" class="img-bordered" src="@Url.Action("RenderImage", new { path= "yourpath" })" height="100" alt="NONE" /> C# Code Action public async Task<ActionResult> RenderImage(string path) { string path = Server.MapPath(path); if (System.IO.File.Exists(path)) { var b = System.IO.File.ReadAllBytes(path); return File(b, "image/jpeg"); } else { string path1 = Server.MapPath("~/noimage.png"); var b = System.IO.File.ReadAllBytes(path1); return File(b, "image/png"); } }
C# MVC Action To Export Data To CSV/EXCEL Document
- Get link
- X
- Other Apps
By
Safeer
-
var gv = new GridView(); StringWriter objStringWriter = new StringWriter(); HtmlTextWriter objHtmlTextWriter; gv.DataSource = Dt; (Set DataTable or List Data) gv.DataBind(); Response.ClearContent(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment; filename=schoollist.xls"); Response.ContentType = "application/ms-excel"; Response.Charset = ""; objStringWriter = new StringWriter(); objHtmlTextWriter = new HtmlTextWriter(objStringWriter); gv.RenderControl(objHtmlTextWriter); Response.Output.Write(objStringWriter.ToString()); Response.Flush(); Response.End(); return View();