473,785 Members | 2,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Exist

ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g() contains the
string path: images/5/Video1/qbert.flv

if (File.Exists(ds 1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g()))
{
//code to execute
}

Despite the path exist along with the file name, the code never gets
executed.
How do I solve the problem?
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Apr 6 '07 #1
5 4634
if your code does not have read access, then exists will return false

-- bruce (sqlwork.com)

Eugene Anthony wrote:
ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g() contains the
string path: images/5/Video1/qbert.flv

if (File.Exists(ds 1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g()))
{
//code to execute
}

Despite the path exist along with the file name, the code never gets
executed.
How do I solve the problem?
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Apr 6 '07 #2
You might want to ensure the path actually exists... images directory is
from the location the code is executing, so if you are in a subfolder but
your path is expected from root, then your path will not exist.

--
Best regards,
Dave Colliver.
http://www.DerbyFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

"bruce barker" <no****@nospam. comwrote in message
news:ui******** ******@TK2MSFTN GP03.phx.gbl...
if your code does not have read access, then exists will return false

-- bruce (sqlwork.com)

Eugene Anthony wrote:
>ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g() contains the
string path: images/5/Video1/qbert.flv

if (File.Exists(ds 1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g()))
{
//code to execute
}

Despite the path exist along with the file name, the code never gets
executed.
How do I solve the problem?
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***

Apr 6 '07 #3
I'd be inclined to break up my statement so that evaluation of the parameter
isn't done inside the method call, e.g.

string path = ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g();
// you can put a breakpoint on the above line to satisfy that the path is
legit.
if (File.Exists( path) {
......
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Eugene Anthony" wrote:
ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g() contains the
string path: images/5/Video1/qbert.flv

if (File.Exists(ds 1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g()))
{
//code to execute
}

Despite the path exist along with the file name, the code never gets
executed.
How do I solve the problem?
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***
Apr 6 '07 #4
The System.IO.File class, and other System.IO classes are designed to work
with file and folder paths. What you have stored in your database is a
virtual path. In fact, it is a relative virtual path.

To explain a bit:

There are several different kinds of paths for different things. Among these
are file and folder paths, UNC paths (network paths), and virtual paths (web
paths). Here are some examples of each:

File Path examples:

foo.txt (relative file path to file in same folder as executing assembly)
C:\somefolder\f oo.txt (absolute file path to file)
..\parentfolder \foo.txt (relative path to file in parent folder of executing
assembly)

Virtual Path examples:

foo.txt (virtual path to file in same virtual directory as web application)
/somefolder/foo.txt (root-relative virtual path to file)
.../siblingfolder/foo.txt (relative virtual path to sibling virtual folder
location of file)

UNC Path example:
\\machine\C\foo .txt (UNC path to file in share C in machine "machine"

Now, you're working in an ASP.Net application, which means that you're
workiing in the context of a web application. The web application has no
knowledge of the file system on the machine, only the virtual directories of
the application. To get at the file system location on the machine, you have
to get the path to it from the web server, or HttpServerUtili ty class. The
HttpServerUtili ty class has a method for doing this translation:
MapPath(virtual path). The HttpServerUtili ty is available as the Server
property of a Page.

However, you're storing relative paths in your database, which means that
the path is relative to the location of the virtual folder containing the
executing page in the web application. Of course, that will be different in
each folder of your web application. So, first you have to determine what
the beginning of the path is relative TO, and then pass a meaningful path
which is relative to the currently-executing page to the Server.MapPath( )
method.

As an example, let's suppose that these are all relative to the root folder
of your web application. For example, your web application is at
http://localhost. The path "images/5/Video1/qbert.flv" - relative to the
root folder of your app would be http://localhost/images/5/Video1/qbert.flv.
Now, let's pretend that the executing page is in the folder
http://localhost/example. The path "images/5/Video1/qbert.flv" - relative to
THAT folder would translate to
http://localhost/example/images/5/Video1/qbert.flv. You don't want that. So,
you need to determine the root-relative path first.

I hope you're still with me, because it gets a bit dodgy from here. Your web
application may not be in the root folder of a web site. It may, for
example, be in http://localhost/web1. Now, using a root-relative path means
that the application root folder is going to be C:\inetpub\wwwr oot\web1, not
C:\inetpub\wwwr oot. If the image is in C:\inetpub\wwwr oot\web1\images , the
root-relative path to it will be \web1\images, rather than \images. But you
may be developing on a local web server with 1 web site and many sub-web
applications, for deployment to a root web site. How do you keep things
synchronized without changing code?

Well, here's where it pays off if your stored paths are relative to the
application root. You can get the absolute path to the web application root
fairly easily, using the Request object. The Request.Applica tionPath
property yields the root-relative web application path. In the example of
http://localhost/web1, this would yield "/web1". You can now use this to
build a root-relative path to the file. Of course, it looks like your stored
path doesn't begin with a slash, so you will need to append it in, as in:

string rootRelative = Request.Applica tionPath + "/" +
ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g();

Now, you pass that to the Server.MapPath method to get the absolute path to
the file:

string filePath = Server.MapPath( rootRelative)

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net

"Eugene Anthony" <so***********@ yahoo.comwrote in message
news:uL******** ******@TK2MSFTN GP05.phx.gbl...
ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g() contains the
string path: images/5/Video1/qbert.flv

if (File.Exists(ds 1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g()))
{
//code to execute
}

Despite the path exist along with the file name, the code never gets
executed.
How do I solve the problem?
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***

Apr 6 '07 #5
I would hazard a guess that if your path does in fact contain
"images/5/Video1/qbert.flv" that its not a complete and understandable file
path. A file path would probably be something c:\images\5\Vid eo1\qbert.flv

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Eugene Anthony" <so***********@ yahoo.comwrote in message
news:uL******** ******@TK2MSFTN GP05.phx.gbl...
ds1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g() contains the
string path: images/5/Video1/qbert.flv

if (File.Exists(ds 1.Tables[0].Rows[0].ItemArray.GetV alue(0).ToStrin g()))
{
//code to execute
}

Despite the path exist along with the file name, the code never gets
executed.
How do I solve the problem?
Eugene Anthony

*** Sent via Developersdex http://www.developersdex.com ***

Apr 6 '07 #6

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

Similar topics

2
7127
by: Lin Ma | last post by:
Greetings, Is it possbile to check a file exist without using Server.CreateObject("Scripting.FileSystemObject") in asp page?? The reason is our hosting company turn that function off for security reason. Here is my original code: <%
23
11426
by: batels | last post by:
Hey All, I'm a bit new at this,and i tryed seraching google about it but i didn't quite got a solution. I'm writing an HTML page that needs to check if another html file exist (in the same folder) and if not,to call to a C file and create that html file. I tryed to do that with JavaScript but i understood there is no such option. Can u advice? and once i know that file doesn't exist,can i call to a C file from a
7
33470
by: andylcx | last post by:
Hi all: The c++ language can check whether the file exist or not. I am wondering how c language does this job? Thanks a lot! Andy
3
4872
by: Dave | last post by:
How can i check to see if a link (file) exist while a web page is loading. If the page doesn't exist - i want the hyperlink to go an error page telling the user the link doesn't exist otherwise they will just go the link which is a pdf file. I'm using asp.net 2003. thanks Dave
52
7545
by: paytam | last post by:
Hi all Can anyone tell me how can I check that a file exist or no.I mean when you use this commands FILE *fp; if(!fp) //Could not open the file doen't show why it can not open it,may be the file doesn't exist.Now tell me what should I do! Thanks
2
1490
by: tino | last post by:
I use File.Exist to check whether a certain image exists. Upon successfull check I want to use the file further but I always get a "The process cannot access the file because it is being used by another application". If I do the same exercise with another type (.MID) it works just fine. Anyone ever come across this? Grateful for all the help.
2
1985
by: Jeff | last post by:
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"))
1
1661
by: siwoodworker | last post by:
Hey all- I am trying to move files when they become avaiable, but am having no luck. Everything I have read talks about using IO.File.Exist(myfile), but this still does not work. I thought about trying to change the name, but that seemed kind of left handed. Any suggestions...This is what I thinking. If fileready(myfile) Then 'Move file Else 'Count or do something then try again. End if.
8
2622
by: Anthony Papillion | last post by:
Hello Everyone, I'm writing some code that needs to check if a file exists or not. I'm using the System.IO's File.Exist() method and it's either misreporting or I am not fully understanding how this class works. Here's what I am doing: if(File.Exist("app.cfg")){ FileStream oFile = new FileStream("app.cfg", FileMode.Open, FileAccess.Read);
1
2243
by: Adya | last post by:
Hi all, I have a list of files starting with a 4 digit code as below, 1) MI01_xxxx_xxxxx.pdf 2) MI01_xxx.pdf 3) MI01_xxxxx.pdf 4) MI03_xxxxx_xxxxx_xxxx.pdf 5) MI04_xxxxxxx_xxxx.pdf 6) MI04_xxx_xxx_xxxxxxxxxxx.pdf
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.