How to get relative path of image for src attribute
pI want to display list of images on my asp.net web page. The pictures are
located in folder. My aspx code looks like this/p precode lt;asp:ListView
runat=server ID=lvPicturePathsgt; lt;ItemTemplategt; lt;img src=lt;%#
Container.DataItem %gt; /gt; lt;/ItemTemplategt; lt;/ListViewgt; /code/pre
pIn code behind I have:/p precode private void GetImagePaths() {
Listlt;stringgt; pathForPictures=new Listlt;stringgt;(); var
path=Server.MapPath(~/images/); foreach(var PP in
Directory.GetFiles(path)) { pathForPictures.Add(PP); }
lvPicturePaths.DataSource=pathForPictures; lvPicturePath.DataBind(); }
/code/pre pThe problem is that src attribute of the img tag need relative
path, something like codelocalhost/images.../code Now I get something
like: code C:\Inetpub\wwwroot\images\image1.jpg /code/p
No comments:
Post a Comment