D
dpfollmer
I am currently designing a ASP.NET form for contacts which displays a
picture depending on which contact is being viewed. This code works
perfectly thus far, but I want to add an if-case for when the picture
does not exist.
In english it would be something like this:
If file exists ("../picture_id.jpg")
Then display image source (<img src='pictures/picture_id.jpg'>
Else diplay nothing (<br><br>)
How do I verify that a file exists on the web server using c#?
Here is a "cleaned" snippet from my current .cs file:
protected Literal imageSRC;
protected override void MyPageLoad(object src, EventArgs e)
{
int picture_id = -1;
try
{
picture_id = Convert.ToInt32(Request["picture_id"]);
}
catch
{
picture_id = -1;
}
if (picture_id > 0)
// <summary> Add if image exists code here </summary>
{
imageSRC.Text = "<img src='contacts_pictures/" + picture_id +
"_Thumb.jpg'>";
}
}
Thanks in advance,
David
picture depending on which contact is being viewed. This code works
perfectly thus far, but I want to add an if-case for when the picture
does not exist.
In english it would be something like this:
If file exists ("../picture_id.jpg")
Then display image source (<img src='pictures/picture_id.jpg'>
Else diplay nothing (<br><br>)
How do I verify that a file exists on the web server using c#?
Here is a "cleaned" snippet from my current .cs file:
protected Literal imageSRC;
protected override void MyPageLoad(object src, EventArgs e)
{
int picture_id = -1;
try
{
picture_id = Convert.ToInt32(Request["picture_id"]);
}
catch
{
picture_id = -1;
}
if (picture_id > 0)
// <summary> Add if image exists code here </summary>
{
imageSRC.Text = "<img src='contacts_pictures/" + picture_id +
"_Thumb.jpg'>";
}
}
Thanks in advance,
David