Show all the images of a directory on my website

0

I have a solution in .Net which has a page that shows my images, I would like it to show all the images of a directory (folder), since there are so many I would not like to spend a lifetime referencing with an img src="" to each one of them I would like to do everything in one, also consider the one that the files will continue adding. I have read forums with codes that do PHP but I do not know how to adapt it, I usually do it like this:

<img src="http://www.deceroadoce.es/wp-content/uploads/2015/11/leopardo-museo-prehistoria-valencia.jpg" class="img-responsive" style="border-radius:10px;" width:300%; height:200%; />
  <img src=" http://jsequeiros.com/sites/default/files/imagen-cachorro-comprimir.jpg" class="img-responsive" style="border-radius:10px;" width:300%; height:200%; />

but what I would like is not to use the src for each image because as I mentioned there are many and with the possibility that they continue to increase, I leave the PHP code that I found but I still do not implement it, thanks

<?php
echo "<h3>Index</h3>\n";
echo "<table>\n";
$directorio = opendir(".");
while ($archivo = readdir($directorio))
   {
   $nombreArch = ucwords($archivo);
   $nombreArch = str_replace("..", "Atras", $nombreArch);
   echo "<tr>\n<td>\n<a href='$archivo'>\n";
   echo "<img src='./imagenes/carpeta.png' alt='Ver $nombreArch'";
   echo " border=0>\n";
   echo "<b>&nbsp;$nombreArch</b></a></td>\n";
   echo "\n</tr>\n";
   }
closedir($directorio); 
echo "</table>\n";
?>
    
asked by Juan Fernando Dj Jf 21.04.2018 в 19:12
source

1 answer

1

Use the following solution, taking into consideration the files that you are ready below:

MasterPage.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!DOCTYPE html>

<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" MasterPageFile="~/MasterPage.master" Inherits="_Default" %>

 <asp:Content ID="Content1" runat="server" ContentPlaceHolderID="head">
 </asp:Content>

 <asp:Content ID="Content2" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
 </asp:Content>

Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.IO;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Image nuevaImagen;
        ContentPlaceHolder contenido = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");

        string[] imagenes = Directory.GetFiles(Server.MapPath("/img/"));
        foreach (var img in imagenes)
        {
            nuevaImagen = new Image();
            nuevaImagen.ImageUrl = "/img/" + Path.GetFileName(img);
            contenido.Controls.Add(nuevaImagen);
        }
    }
}
  

It is good to emphasize that you have a Website type project in ASPX.

    
answered by 21.04.2018 / 23:26
source