displays image from another folder in asp.net

Posted by Klbaiju under ASP.NET on 3/21/2018 | Points: 10 | Views : 2227 | Status : [Member] | Replies : 1
Hi,

I want to display an image in my application from another folder.

my application in E drive and images in D folder.

I have tried below code

welcomeimages.ImageUrl =@"D:\writereaddata\UnitPhotos\" + dt.Rows[0]["PhotoUrl"].ToString();

no error have showed. but image doesn't shown


how to solve this

Regards

Baiju




Responses

Posted by: Vedikaledange on: 1/3/2019 [Member] Starter | Points: 25

Up
0
Down
You may try with this code
Imports System.IO

Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

Dim iFileCnt As Integer = 0

Dim dirInfo As New System.IO.DirectoryInfo(Server.MapPath("~/images/theme/"))
Dim listfiles As FileInfo() = dirInfo.GetFiles("*.*")

If listfiles.Length > 0 Then
For Each file As FileInfo In listfiles

' CHECK THE TYPE OF FILE.
If Trim(listfiles(iFileCnt).Extension) = ".jpg" Or _
Trim(listfiles(iFileCnt).Extension) = ".jpeg" Or _
Trim(listfiles(iFileCnt).Extension) = ".png" Or _
Trim(listfiles(iFileCnt).Extension) = ".bmp" Or _
Trim(listfiles(iFileCnt).Extension) = ".gif" Then

Dim img As New HtmlImage
Dim newDiv As New HtmlGenericControl("div")
Dim textDiv As New HtmlGenericControl("div")

' ADD IMAGE.
img.Src = "~/images/theme/" & listfiles(iFileCnt).Name
img.Width = "130"
img.Height = "130"

newDiv.Attributes.Add("style", "float:left;padding:5px 3px;
margin:20px 3px;height:auto;overflow:hidden;")
newDiv.Controls.Add(img)

' ADD A TEXT.
textDiv.Attributes.Add("style", "display:block;font:13px Arial;padding:10px 0;width:" & _
img.Width & "px;color:#666;text-align:center;cursor:pointer;")

textDiv.InnerText = "Various Catgories - Binding, Product Specification, Author (Price Tag)"
newDiv.Controls.Add(textDiv)

divGallary.Controls.Add(newDiv)

End If

iFileCnt = iFileCnt + 1

Next
End If
End Sub
End Class

DOT NET

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response