Listview Image Library how to get full path of image

I have an asp.net  listview control that populates an image library (code below),  the property  ImageVirtualDir
returns the virtual directory path to the image as all images are located within a folder in the application.

I want to display the full path of the image however currently I am only displaying the path and image name like this...

<asp:Label ID="path" runat="server" Text='<%#Eval("ImageVirtualDir").ToString() %>'>

So this would display like          "ImageVirtualDir/Image19.jpg"

I need it so it displays the FULL path like this

"http://www.mytestsite.com/ImageVirtualDir/Image19.jpg"

Thanks


<img src="<%#Eval("ImageVirtualDir") %>" />

Open in new window

mugseyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xav056Commented:
Add the following to your aspx page

<asp:Label ID="path" runat="server" Text='<%# FullPath(DataBinder.Eval(Container.DataItem,"ImageVirtualDir") %>'>

and add the fullpath function to your code behind


protected Function FullPath(imageVirtualDirectory as string) As String
return System.Web.HttpContext.Current.Request.Url.Scheme & Uri.SchemeDelimiter & System.Web.HttpContext.Current.Request.Url.Authority &"/" &imageVirtualDirectory 

    End Function

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nomooseCommented:
Hey Mugsey,

Try using the following...        

<img src="<%#Eval("ImageVirtualDir", "~/{0}) %>" />

When you put "~/" in a string on a tag that is set to runat="server" then you get the full server path created when the page loads and renders.  I use this method in my code to pull and display dynamic images from a DB.
Let me know how it goes,
  Elliot
0
mugseyAuthor Commented:
OK thanks for your replies

You see in the code below the" ImageVirtualDir" is a property of an image object that appends the virtual directory where the images are stored plus he filename.

So with your examples above how would I implement them?




public string ImageVirtualDir
		{
			get
			{
				var urlBase = Properties.Settings.Default.ImageVirtualDir;
				
				if(!urlBase.EndsWith("/"))
					urlBase += "/";

				return urlBase + FileName;                
			}
		}

Open in new window

0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

mugseyAuthor Commented:
You see  I can display the images OK

However I want a label to display the full path of the image,   because the images are stored in a folder within the app I can display the images in the listiew just by using

<img src="<%#Eval("ImageVirtualDir") %>"

However I want a label underneath the image to display the whole path - so currently I have

 <asp:Label ID="imageURL" runat="server" Text='<%#Eval("ImageVirtualDir").ToString() %>'></asp:Label>

that will display     "/ImageVirtualDir/image22.jpg"

But I don't know how to concatenate    the Request.Url.Authority to

Text='<%#Eval("ImageVirtualDir").

so like ??     Text='<%#Eval("URLAuthority" + Eval("ImageVirtualDir").

where  URLAuthority is a page property that returns the path (www.mysitetest.com)  ?
0
nomooseCommented:
Did you try the sample code I posted above?  I know that works...
0
mugseyAuthor Commented:
HI thanks no I got an error "expecting ("


However this is my situation

Eval("ImageVirtualDir") this works fine

Now say I have a page property like this

  public string LeftImageURL
    {
        get
        {
            return Request.Url.GetLeftPart(UriPartial.Authority);
        }
    }

Well can I do something like this

<%# string.Concat(Eval("LeftImageURL"), "/", Eval("ImageVirtualDir"))%>' />
0
CodeCruiserCommented:
Try this

 <asp:Label ID="imageURL" runat="server" Text='<%#Server.MapPath(Eval("ImageVirtualDir").ToString()) %>'></asp:Label>
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.