In your page, you can just do this:
// Get the url.
string url = String.Format("~/images/categories/{0}", sFileName);
// Check to see if the file exists on the server.
if (File.Exists(Server.MapPath(url)))
{
return url;
}
else
{
// Get the url.
url = String.Format("~/images/products/{0}", sFileName);
// Chefk for the existence.
if (File.Exists(Server.MapPath(url)))
{
// Return the url.
return url;
}
// Return an empty string.
return "";
}
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"trint" <tr***********@gmail.comwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
On Apr 23, 11:47 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
>Trint,
Yes, you will have to use the MapPath method to get a path on the
local
machine and then you can use the Exists method on the File class to check
the existence of it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"trint" <trinity.sm...@gmail.comwrote in message
news:11*********************@o5g2000hsb.googlegro ups.com...
How can I do this with my c# code with my website(because the file is
there, but the code doesn't return it)?:
if(File.Exists(String.Format("~/images/categories/{0}", sFileName))
return String.Format("~/images/categories/{0}", sFileName);
else if(File.Exists(String.Format("~/images/products/{0}",
sFileName))
return String.Format("~/images/products/{0}", sFileName);
else
return "";
I thought I might have to use:
Server.MapPath.
Any help is appreciated.
Thanks,
Trint- Hide quoted text -
- Show quoted text -
Can you please give me an example?
Thanks,
Trint