[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to get URL of website via code

Posted on 2010-04-06
6
Medium Priority
?
422 Views
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

0
Comment
Question by:mugsey
  • 3
  • 3
6 Comments
 
LVL 41

Expert Comment

by:guru_sami
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") %>'/>

0
 

Author Comment

by:mugsey
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") %>'/>


0
 
LVL 41

Expert Comment

by:guru_sami
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
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: 29929751
thanks sami

How can add GetFullPath  to markup?

So

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

Accepted Solution

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

Author Comment

by:mugsey
ID: 29934265
Guru Sami

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

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