[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Listview Image Library how to get full path of image

Posted on 2010-04-06
7
Medium Priority
?
600 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:mugsey
7 Comments
 
LVL 9

Accepted Solution

by:
xav056 earned 500 total points
ID: 29918534
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
 
LVL 3

Assisted Solution

by:nomoose
nomoose earned 1000 total points
ID: 29918637
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
 

Author Comment

by:mugsey
ID: 29919300
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 

Author Comment

by:mugsey
ID: 29920846
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
 
LVL 3

Assisted Solution

by:nomoose
nomoose earned 1000 total points
ID: 29922755
Did you try the sample code I posted above?  I know that works...
0
 

Author Comment

by:mugsey
ID: 29923285
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
 
LVL 83

Assisted Solution

by:CodeCruiser
CodeCruiser earned 500 total points
ID: 29951599
Try this

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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.

611 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question