Skip to content

Instantly share code, notes, and snippets.

@rodolfofadino
Created November 25, 2014 16:56
Show Gist options
  • Save rodolfofadino/a623040cd15d9b75b77d to your computer and use it in GitHub Desktop.
Save rodolfofadino/a623040cd15d9b75b77d to your computer and use it in GitHub Desktop.
Exemplo de imagem em url com /
using System.IO;
using System.Web.Mvc;
namespace TDCFrontEnd.Controllers
{
public class HomeController : Controller
{
public ActionResult About()
{
//Acesso ao Database
Response.ContentType = "image/gif";
var imagem =
ReadFile(Server.MapPath("~/Content/cat.gif"));
//Acesso ao Database
Response.BinaryWrite(imagem);
return null;
}
protected byte[] ReadFile(string sPath)
{
byte[] data = null;
var fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
using (var fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read))
{
using (var br = new BinaryReader(fStream))
{
data = br.ReadBytes((int)numBytes);
br.Close();
fStream.Dispose();
return data;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment