mugsey
asked on
How to get URL of website via code
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(Ur iPartial.A uthority) in code behind AND CONCATENATE IT TO <img src="<%#Eval("picPath") %>"
So like www.testsite.com/image22.jpg
How can I contacentate
Request.Url.GetLeftPart(Ur
<img src="<%#Eval("picPath") %>"
ASKER
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") %>'/>
I need to display the full path in text
so something like
TEXT='<%# "~/" +Eval("picPath") %>'/>
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
protected string GetFullPath(string relativepath)
{
//string relativepath = "pic1.jpg";
string domainpath = Request.Url.Scheme + System.Uri.SchemeDelimiter
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
ASKER
thanks sami
How can add GetFullPath to markup?
So
TEXT='<%# "Eval("GetFullPath") +Eval("picPath") %>'/>
How can add GetFullPath to markup?
So
TEXT='<%# "Eval("GetFullPath") +Eval("picPath") %>'/>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Guru Sami
Excellent answer!!!!!!! ;-)
Excellent answer!!!!!!! ;-)
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/" +Eval("picPath") %>'/>