image in datalist

M

mahsa

hi I use the image in datalis
<asp:Imag
ImageUrl='<%#Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(Container.DataItem, "PartNo")+"_ss.jpg") %>' Visible='<%#!System.IO.File.Exists(@"\images\roomscenes\"+DataBinder.Eval(Container.DataItem, "PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" /
but it always return visible=fals
when i use
FileInfo fi = new FileInfo(Server.MapPath(@"\images\roomscenes\"+strFileName+"_ss.jpg"))
if (fi.Exists
{do some thing
it shows the currect answer how can I use it in image tag?
 
M

Michael Tkachev

Don't use MapPath. Because MapPath returns phisical path and you need to get
to virtual path. It's a different.

/// <summary>

/// Returns Phisical path. E.g.: c:\intepub\wwwroot\test\

/// </summary>

public static string PhisicalPath

{

get

{

return
System.Web.HttpContext.Current.Request.MapPath(HttpContext.Current.Request.A
pplicationPath + "/");

}

}

/// <summary>

/// Gets Virtual Directory of the application

/// E.g: microsoft/

/// </summary>

public static String AppVirtualDir //returns virtual directory

{

get

{

return HttpContext.Current.Request.ApplicationPath + '/';

}

}

/// <summary>

/// Gets the host of the application

/// E.g.: Server2

/// </summary>

public static String AppHost //returns host

{

get

{

return HttpContext.Current.Request.Url.Host;

}

}

/// <summary>

/// Returns "http://"

/// </summary>

public static String AppProtocol //returns protocol

{

get

{

return "http://";

}

}


/// <summary>

/// Gets the absolute root of the application

/// E.g.: http://server2/microsoft/

/// </summary>

public static String AppAbsoluteRoot //returns the whole path

{

get

{

return AppProtocol + AppHost + AppVirtualDir;

}

}


mahsa said:
hi I use the image in datalist
<asp:Image
ImageUrl='<%#Server.MapPath(@"\images\roomscenes\"+DataBinder.Eval(Container
..DataItem, "PartNo")+"_ss.jpg") %>'
Visible='<%#!System.IO.File.Exists(@"\images\roomscenes\"+DataBinder.Eval(Co
ntainer.DataItem, "PartNo")+"_ss.jpg") %>' runat="server" ID="Image1" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top