[Webinar] Streamline your web hosting managementRegister Today


How to get URL of website via code

Posted on 2010-04-06
Medium Priority
Last Modified: 2013-12-17
I have an asp.net listview that lists a set of images and underneath the image I want to display the full URL of the image.

So like  www.testsite.com/image22.jpg

How can I contacentate

Request.Url.GetLeftPart(UriPartial.Authority)  in code behind  AND CONCATENATE IT TO  <img src="<%#Eval("picPath") %>"  
<img src="<%#Eval("picPath") %>"

Open in new window

Question by:mugsey
  • 3
  • 3
LVL 41

Expert Comment

ID: 29919961
you can use asp.net image control instead of html img and this will take care of image path mapping

<asp:Image ID="Image1" runat="server"  ImageUrl='<%# "~/" +Eval("picPath") %>'/>


Author Comment

ID: 29922124
Hi thanks but I can display the images OK however

 I need to display the full path in text

so something like

TEXT='<%# "~/" +Eval("picPath") %>'/>

LVL 41

Expert Comment

ID: 29925098
Try this function:
 protected string GetFullPath(string relativepath)
         //string relativepath = "pic1.jpg";
        string domainpath = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.Port != 80 ? ":" + Request.Url.Port : "");
        string applicationpath = Request.ApplicationPath;
        string fullpath = domainpath + applicationpath + "/" + relativepath;
        return fullpath;

Note: If your relative path already has / in front then remove "/" from full path.

Ref: http://stackoverflow.com/questions/61817/whats-the-best-method-in-asp-net-to-obtain-the-current-domain
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

ID: 29929751
thanks sami

How can add GetFullPath  to markup?


TEXT='<%# "Eval("GetFullPath")  +Eval("picPath") %>'/>
LVL 41

Accepted Solution

guru_sami earned 2000 total points
ID: 29931361
TEXT='<%# GetFullPath(Eval("picPath").ToString())%>'/>

Author Comment

ID: 29934265
Guru Sami

Excellent answer!!!!!!!   ;-)

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

607 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