473,399 Members | 2,146 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,399 software developers and data experts.

Problem with File.Exist

Hey

ASP.NET 2.0

Below is the code I have trouble with. I've placed some pictures in the
~/Network/Images/Fullsize/ folder in my project. The problem is that File
Exist always return false (it execute the ELSE block, despite the fact that
~/Network/Images/Fullsize/" + Profile.UserName + ".png" exist)

if (File.Exists("~/Network/Images/Fullsize/" + Profile.UserName + ".png"))
{
imgProfile.ImageUrl = "~/Network/Images/Fullsize/" + Profile.UserName +
".png";
}
else
{
imgProfile.ImageUrl = "~/Network/Images/Fullsize/nopicture.png";
}

What am I doing wrong here?

Jeff
Oct 21 '06 #1
2 1974
On Sat, 21 Oct 2006 16:38:23 +0200, "Jeff"
<it************@hotmail.com.NOSPAMwrote:
>Below is the code I have trouble with. I've placed some pictures in the
~/Network/Images/Fullsize/ folder in my project. The problem is that File
Exist always return false (it execute the ELSE block, despite the fact that
~/Network/Images/Fullsize/" + Profile.UserName + ".png" exist)

if (File.Exists("~/Network/Images/Fullsize/" + Profile.UserName + ".png"))
I would try with Server.MapPath( "~/Network...." ) to get the physical
path of the file. If it doesn't work, try losing tilde (~). I don't
think it would work what's it meant to do in the codebehind.

rb
Oct 21 '06 #2
Only aspx pages understand the ~ syntax. File.Exists doesn't. MapPath
("Network...") will do the trick.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Rajko Bogdanovic - DX Squad" <ra****@dxsquad.comwrote in message
news:2n********************************@4ax.com...
On Sat, 21 Oct 2006 16:38:23 +0200, "Jeff"
<it************@hotmail.com.NOSPAMwrote:
>>Below is the code I have trouble with. I've placed some pictures in the
~/Network/Images/Fullsize/ folder in my project. The problem is that File
Exist always return false (it execute the ELSE block, despite the fact
that
~/Network/Images/Fullsize/" + Profile.UserName + ".png" exist)

if (File.Exists("~/Network/Images/Fullsize/" + Profile.UserName + ".png"))

I would try with Server.MapPath( "~/Network...." ) to get the physical
path of the file. If it doesn't work, try losing tilde (~). I don't
think it would work what's it meant to do in the codebehind.

rb

Oct 22 '06 #3

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

Similar topics

1
by: Michael J Whitmore | last post by:
I am getting tired of losing hair over this. Here is a function that simply inserts one of three images into a document right before printing. It is called for every element that has a specific...
1
by: wongjoekmeu | last post by:
Hello all, I have the following problem. I have a function which being called several times during the run of my program. When the function is called for the first time I want it to create a file...
20
by: Steevo | last post by:
For some reason I can't seem to get the contact form on our website to work any longer. I think I must have something wrong in the script because I keep getting an "Internal Server Error" upon...
3
by: Jagdip Singh | last post by:
Hi, We are facing problem accessing to DB2. Seems like database manager is down I tried starting it using db2start but it was neither showing any messages nor returning to command prompt...
0
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to...
5
by: VB Programmer | last post by:
I want to write to a simple text file. If it doesn't exist I want to create it first. Here is my code (portion): Imports System.IO ' at the top of the class : : Dim strFileName As String =...
12
by: NOO Recursion | last post by:
Hi everyone! I am trying to write a program that will search a 12x12 for a thing called a "blob". A blob in the grid is made up of asterisks. A blob contains at least one asterisk. If an...
0
by: james.mcdonagh | last post by:
Hi I am a newbie using nAnt for .net 2.0. As such I have not come across this bug before, and I would be happy of any help that you may be able to provide. In order to help I have included the...
1
by: jamesmcdonagh | last post by:
Hi newbie using nAnt for .net 2.0. I would be happy of any help that you may be able to provide. The weird thing is that VS.net builds without a problem. And the intellisense within the object...
9
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.