2
Good afternoon, I’m trying to make an API to return the URL of an image list but I don’t know how to do it.
I found things with server.mapPatch
but these return the physical address of the file.
I wanted to return the type URL like this:
www.meusite.com.br/conteudo/categoria/foto.jpg
I did so but returns me the physical path, wanted mine URL
public JsonResult Fotos()
{
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("~/Content/imagens/categoria"));
var lista = new List<string>();
foreach (var item in dirInfo.GetFiles())
{
lista.Add(item.FullName);
}
return Json(lista, JsonRequestBehavior.AllowGet);
}
I managed to do it this way but it got ugly, it seems like I was :C
var dominio = "http://localhost:53592";
DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("~/Content/imagens/categoria"));
var lista = new List<string>();
foreach (var item in dirInfo.GetFiles())
{
lista.Add(dominio + "/Content/imagens/categoria/" + item.Name);
}
return Json(lista, JsonRequestBehavior.AllowGet);
That’s what I wanted, thanks
– Rafael Scheffer