asp.net Web ページに画像の一覧を表示したいと考えています。写真はフォルダにあります。私のaspxコードは次のようになります
<asp:ListView runat="server" ID="lvPicturePaths">
<ItemTemplate>
<img src="<%# Container.DataItem %>" />
</ItemTemplate>
</ListView>
コードビハインドには次のものがあります。
private void GetImagePaths()
{
List<string> pathForPictures=new List<string>();
var path=Server.MapPath("~/images/");
foreach(var PP in Directory.GetFiles(path))
{
pathForPictures.Add(PP);
}
lvPicturePaths.DataSource=pathForPictures;
lvPicturePath.DataBind();
}
問題は、img タグの src 属性に相対パスが必要なことです。たとえば、次のようなlocalhost/images...
ものが得られます。 C:\Inetpub\wwwroot\images\image1.jpg