<asp:Image ID="imgGrad" runat="server" BorderColor="DimGray"
BorderStyle="Solid" BorderWidth="1px" Height="120px" ImageUrl='<%#
"~/Images/ClassmatePics/" & Eval("GradPhotoFileName") %>' ToolTip="Click to
enlarge" /></td>
"GradPhotoFileName" is stored in a field in a table. If the file name stored
in the table is "JeffJones.jpg" but there is no "JeffJones.jpg" file in the
"~/Images/ClassmatePics/" folder then I have a dummy jpg image that I want
to show ("MissingPhoto.jpg").
I'm hoping there's an easy way to do that maybe in the EVAL code but I don't
know how. Can someone help me out?
Thanks,
Keith
THanks,
Keith
"Peter Bromberg [C# MVP]" <pbro...@nospammaam.yahoo.com> wrote in message
news:30141463-D7AF-4A95...@microsoft.com...
--
---------------------------------------------------
S.M. Altaf [MVP]
http://www.mendhak.com/
"Keith G Hicks" <k...@comcast.net> wrote in message
news:#maMeNyq...@TK2MSFTNGP04.phx.gbl...
The following markup for an asp:image is in an aspx file in my root folder:
<asp:Image runat="server" ID="imgGradLarge" ImageUrl='<%#
imageFileToDisplay("~/Images/ClassmatePics/", val("GradPhotoFileName"))
%>'></asp:Image>
This VB.net code is in my App_Code folder in a file caled MyUtils.vb
Public Shared Function imageFileToDisplay(ByVal imageFilePath As String,
ByVal imageFileName As String) As String
If System.IO.File.Exists(imageFilePath & "/" & imageFileName) Then
imageFileToDisplay = imageFilePath & "/" & imageFileName
Else
imageFileToDisplay = imageFilePath & "/NoClassmatePic.jpg"
End If
End Function
I'm sure there's more wrong that I am not aware of but for starters I get
this error:
Compiler Error Message: BC30451: Name 'imageFileToDisplay' is not declared.
If you are tempted to respond with "You need to declare
'imageFileToDisplay'" then please don't respond. I need to know HOW to do
that in the aspx markup. I haven't found anything that explains how to do
that.
If you see anything else I need to correct, please feel free to be as
specific as possible.
I really need specific coding help. I'm a bit lost on this right now. Pseudo
code suggestions are not what I'm looking for. I need someone to either show
me (I'm still learning) how to corrrect the above code or at least point me
to a website that expains (with actual example code) how to do what I'm
trying to do.
Keith
"Keith G Hicks" <k...@comcast.net> wrote in message
news:eZP7Atxq...@TK2MSFTNGP05.phx.gbl...
Protected Function imageFileToDisplay(ByVal imageFilePath As String,
ByVal imageFileName As String) As String
If File.Exists(ResolveUrl(imageFilePath) & imageFileName) Then
imageFileToDisplay = imageFilePath & imageFileName
Else
imageFileToDisplay = imageFilePath & "NoClassmatePic.jpg"
End If
End Function
and it runs without errors. The problem is that the
ResolveUrl(imageFilePath) only returns part of the path like this:
/mysite/...
but I need
C:\Inetpub\wwwroot\mysite\......
What vb.net function will give me this?
Keith
"Keith G Hicks" <k...@comcast.net> wrote in message
news:eI3NFe4...@TK2MSFTNGP02.phx.gbl...
Not sure, but if your markup is calling imageFileToDisplay, then you should
be able to change both of the imageFileToDisplay in your IF and ELSE
statements to return... i.e.
return imageFilePath & "/NoClassmatePic.jpg"
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Keith G Hicks" <k...@comcast.net> wrote in message
news:eI3NFe4...@TK2MSFTNGP02.phx.gbl...
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Keith G Hicks" <k...@comcast.net> wrote in message
news:erfrou4q...@TK2MSFTNGP02.phx.gbl...
My code behind function is as follows (with Imports System.IO at the top of
the file):
Protected Function imageFileToDisplay(ByVal imageFileName As String) As
String
If File.Exists(System.AppDomain.CurrentDomain.BaseDirectory &
"Images\ClassmatePics\" & imageFileName) Then
imageFileToDisplay = "~/Images/ClassmatePics/" & imageFileName
Else
imageFileToDisplay = "~/Images/ClassmatePics/NoClassmatePic.jpg"
End If
End Function
System.AppDomain.CurrentDomain.BaseDirectory is getting the entire path of
the site's root (C:\Inetpub\wwwroot\mySite for example). I suppose I could
have passed the path from the aspx file to the code behind but it's 6 of
one, 1/2 dozen of the other IMO. I didn't use ResolveURL because that
doesn't give the the whole base path.
My markup in the aspx page is as follows:
<asp:Image ID="imgGrad" runat="server" BorderColor="DarkGray"
BorderStyle="Solid" BorderWidth="1px" Height="130px" ImageUrl='<%#
imageFileToDisplay(Eval("GradPhotoFileName")) %>' ToolTip="Click to enlarge"
/>
it all works perfectly fine.
Keith
"Keith G Hicks" <k...@comcast.net> wrote in message
news:eQdnK45q...@TK2MSFTNGP06.phx.gbl...
imgGrad.Attributes("onerror") = "this.src='<dummy image relative path>;'"
That will cause the user's browser to load the dummy image if it doesn't
find the original.
Hope that helps,
Fernando Rodriguez, MCP
"S.M. Altaf [MVP]" <sma...@omgplzdntspammekthxbaimsn.com> wrote in message
news:3F211D0B-3873-4089...@microsoft.com...