Created
November 25, 2014 16:56
-
-
Save rodolfofadino/a623040cd15d9b75b77d to your computer and use it in GitHub Desktop.
Exemplo de imagem em url com /
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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