473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

I need to check for existence of a file on our website in "images"...

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

Apr 23 '07 #1
3 4149
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]
- mv*@spam.guard.caspershouse.com

"trint" <tr***********@gmail.comwrote in message
news:11*********************@o5g2000hsb.googlegrou ps.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

Apr 23 '07 #2
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.googlegrou ps.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

Apr 23 '07 #3
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

Apr 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dante | last post by:
Just a thought: what if you posted the W3C's "Valid XHTML" images on a webpage that doesn't even use XHTML? Or with a Valid CSS thing. What could the W3C do to you anyway? Maybe I'll do that just...
9
by: Don | last post by:
Does anyone know where I can find a client-side function I can reference from within an HTML/JavaScript web page? I'm currently using a core PHP function to do this, but I'd rather do it on the...
2
by: Delali Dzirasa | last post by:
I am a newbie and am creating my first asp.net in crystal reports. I have created the report (.rpt file) and have dropped the CrystalReportViewer on the web form. From the databinding...
8
by: Maxwell2006 | last post by:
Hi, Using ASP.NET 2.0, I have this tag in my asp page: <td runat =server background="~/Images/Header2.gif">&nbsp;</td> The problem is when I run the page, the server side TD tag renders...
2
by: Chuck Anderson | last post by:
I have a web page/script that displays image files residing on disk. I do not know what size they are (in pixels), so I want to be able to resize an image if it is bigger than the limit I allow...
2
by: yawnmoth | last post by:
imagestring essentially turns text strings into images. Unfortunately, these images can be of any size and, as far as I know, an images size needs to be decided upon before imagestring is called....
5
eragon
by: eragon | last post by:
I wrote this function to create a new file when the user posts in my forums, and its not creating a new file, can you help me? this script is not copyrighted as the last one. function...
5
by: krille | last post by:
I have a problem.... I need to send a graph via email from an asp.net (c#) web app. My Graph is buildt by an <ul> and css. When I mail this created HTML it doesnt show the right way in outlook but...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.