472,958 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 4124
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.