Hi Group,
I encountered something strange with File.Exists(string path). This
function is simply to check whether a file exists in certain path. However,
if the path starts with "file:\" in the begining of the string, no matter
the file exists or not. it will return false without any exception. It is
expected?
Regards,
Alex 6 6011
I'm curious. What version of windows os allows you have "file" as a drive
letter?
"Alex Chan" <Ga********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl... Hi Group,
I encountered something strange with File.Exists(string path). This function is simply to check whether a file exists in certain path.
However, if the path starts with "file:\" in the begining of the string, no matter the file exists or not. it will return false without any exception. It is expected?
Regards, Alex
Nope. for example, the path like that "file:\c:\temp\foo.txt" will return
false in every case, while "c:\temp\foo.txt" wont
"ESPN Lover" <es**@lover.com> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl... I'm curious. What version of windows os allows you have "file" as a drive letter?
"Alex Chan" <Ga********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... Hi Group,
I encountered something strange with File.Exists(string path). This function is simply to check whether a file exists in certain path. However, if the path starts with "file:\" in the begining of the string, no
matter the file exists or not. it will return false without any exception. It
is expected?
Regards, Alex
So then what's the issue? If you're checking for a malformed file path, you
should get false. Simply strip off the file:\ from your string
Try this:
if (p.IndexOf(@"file:\") == 0)
p = p.Substring(6);
"Alex Chan" <Ga********@hotmail.com> wrote in message
news:em**************@TK2MSFTNGP12.phx.gbl... Nope. for example, the path like that "file:\c:\temp\foo.txt" will return false in every case, while "c:\temp\foo.txt" wont
"ESPN Lover" <es**@lover.com> wrote in message news:eD**************@TK2MSFTNGP11.phx.gbl... I'm curious. What version of windows os allows you have "file" as a
drive letter?
"Alex Chan" <Ga********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... Hi Group,
I encountered something strange with File.Exists(string path).
This function is simply to check whether a file exists in certain path. However, if the path starts with "file:\" in the begining of the string, no matter the file exists or not. it will return false without any exception. It is expected?
Regards, Alex
Hi,
The reason why i felt that strange is the "file:\" is come with
Path.GetDirectoryName. My idea is to determine the location of the config
file storing in the current path of the executable through the following
szConfigFileName=
Path.GetDirectoryName(Assembly.GetExecutingAssembl y().CodeBase) +
"\\Config.xml";
For this, you will get the path starting with "file:\", and i check that
with File.Exists before opening the file, it always return false and none of
the settings got read.
Actually your suggestion is what i am using.
Regards,
Alex
"ESPN Lover" <es**@lover.com> wrote in message
news:uF**************@TK2MSFTNGP11.phx.gbl... So then what's the issue? If you're checking for a malformed file path,
you should get false. Simply strip off the file:\ from your string
Try this: if (p.IndexOf(@"file:\") == 0)
p = p.Substring(6); "Alex Chan" <Ga********@hotmail.com> wrote in message news:em**************@TK2MSFTNGP12.phx.gbl... Nope. for example, the path like that "file:\c:\temp\foo.txt" will
return false in every case, while "c:\temp\foo.txt" wont
"ESPN Lover" <es**@lover.com> wrote in message news:eD**************@TK2MSFTNGP11.phx.gbl... I'm curious. What version of windows os allows you have "file" as a drive letter?
"Alex Chan" <Ga********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl... > Hi Group, > > I encountered something strange with File.Exists(string path). This > function is simply to check whether a file exists in certain path. However, > if the path starts with "file:\" in the begining of the string, no matter > the file exists or not. it will return false without any exception.
It is > expected? > > Regards, > Alex > >
Alex Chan wrote: Hi,
The reason why i felt that strange is the "file:\" is come with Path.GetDirectoryName. My idea is to determine the location of the config file storing in the current path of the executable through the following
szConfigFileName= Path.GetDirectoryName(Assembly.GetExecutingAssembl y().CodeBase) + "\\Config.xml";
For this, you will get the path starting with "file:\", and i check that with File.Exists before opening the file, it always return false and none of the settings got read.
Actually your suggestion is what i am using.
Regards,
Alex
"ESPN Lover" <es**@lover.com> wrote in message news:uF**************@TK2MSFTNGP11.phx.gbl...
So then what's the issue? If you're checking for a malformed file path,
you
should get false. Simply strip off the file:\ from your string
Try this: if (p.IndexOf(@"file:\") == 0)
p = p.Substring(6); "Alex Chan" <Ga********@hotmail.com> wrote in message news:em**************@TK2MSFTNGP12.phx.gbl...
Nope. for example, the path like that "file:\c:\temp\foo.txt" will return false in every case, while "c:\temp\foo.txt" wont
"ESPN Lover" <es**@lover.com> wrote in message news:eD**************@TK2MSFTNGP11.phx.gbl...
I'm curious. What version of windows os allows you have "file" as a
drive
letter?
"Alex Chan" <Ga********@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl.. .
>Hi Group, > > I encountered something strange with File.Exists(string path).
This
>function is simply to check whether a file exists in certain path.
However,
>if the path starts with "file:\" in the begining of the string, no
matter
>the file exists or not. it will return false without any exception. It is
>expected? > > Regards, >Alex > >
Sounds like you're using remoting.
System.IO.File.Exists works on the local machine only. It works the same
way as any other file on a local machine e.g. "c:\hello.txt"
You MUST be doing something using remoting otherwise it will return the
path on the local machine.
If not you are doing something so strange that I've yet to meet it.
Darwen.
"Alex Chan" <Ga********@hotmail.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl... szConfigFileName= Path.GetDirectoryName(Assembly.GetExecutingAssembl y().CodeBase) + "\\Config.xml";
I believe for this, yo'd want:
szConfigFileName=
Path.GetDirectoryName(Server.MapPath(Assembly.GetE xecutingAssembly().CodeBas
e)) +
"\\Config.xml";
"file://" is a URL protocol, like "http://" or "ftp://". File.Exist doesn't
understand it. MapPath converts a URL address to a local disk address.
--
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mike Schinkel |
last post by:
Does anyone know if there are bugs in VBScript's GetRef()? I'm using
VBScript Version 5.6.8515 on Win2003Server w/ASP.
Sometimes it returns an object that VarType() says is a vbObject. Other...
|
by: Geiregat Jonas |
last post by:
is using
if(open("file",O_EXCL) != -1){ printf("File does
exists")}else{printf("file does not exists"); }
a good way of checking if a file exists or not, if not how should I do it ?
|
by: StGo |
last post by:
How can i read/write file's custom attributs(like subject,author...) in
C#???
Thanks :))
|
by: Dan |
last post by:
I have code like the following to test for existence of a file. I know the
file is there, but File.Exists returns FALSE. The problem appears to be
that the file is in a directory beneath "My...
|
by: Chris Fink |
last post by:
I am using the System.IO.File class to determine if a file exists on a
network share.
The File.Exists method keeps returning false, even though the file does
exist. The MSDN documentation...
|
by: DEWright_CA |
last post by:
I am trying to see if a file exists in a virtual directory, and if so run a
method. I try doing File.Exists and the method runs but the file isn't there.
Is there a web version of File.Exists or...
|
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...
|
by: Peter Duniho |
last post by:
I searched using Google, on the web and in the newsgroups, and found nothing
on this topic. Hopefully that means I just don't understand what I'm
supposed to be doing here. :)
The problem:
...
|
by: PawelSokolowski |
last post by:
Hi all,
Is there any place where can I report bugs in Microsoft products in a way
that gives somethings ?
I mean anyone there cares ?
I was coping with bugs in Visual Studio for years, but I...
|
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,...
|
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,...
|
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...
|
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...
|
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...
|
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: 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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
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 ...
| |