I was using below code until I get too many images. So I wanted to make a method in the master page cs file class to rather generate the HTML for me.
<img src="<%= ResolveUrl("~/images/1.png") %>">
But as long I get a lot of images I wrote this method to generate the HTML:
public void GenerateSlideItems()
{
string[] files = Directory.GetFiles(Server.MapPath("~/images"));
foreach(string file in files)
{
string filename = Path.GetFileNameWithoutExtension(file);
Response.Write(string.Format(
"<img src=\"{0}\" class=\"img-responsive\" alt=\"{1}\">",
file, filename));
}
}
But I'm getting the images like C:\...\visual studio\project\etc\1.png
rather http:\\localhost:5090\images\1.png
how do I do that? I also tried with and without ResolveUrl()
but it ended up returning something like C:\images\1.png
which obviously isn't the correct path I'm looking for. I new to ASP.NET I don't know yet how those things are usually done. I'm learning.