Home All Groups Group Topic Archive Search About

Problem with FileInfo class

Author
5 Sep 2006 1:23 PM
eduwushu
Hi i have an application wich have to retrieve information of files. I have
an openfiledialog on which i cans elect a file and then i retrieve the path
to the file selected on it by the user.I create a FileInfo object with that
path
Well when i later try to create a new fileinfo object passing to the
constructor teh relative path of another file it cant find the file because
automatically it puts the path i used before to create another fileinfo
object at the beginning of my path. For example if i create a first File Info
object this way:

FielInfo info=new FileInfo("C:\Program Files\Folder\hello.txt");

when i try to create this second

FileInfo info=new FileInfo("goodbye.txt");

it throws me an exception saying that the file "C:\Prtogram
Files\Folder\goodbye.txt" doesnt exists. (Of course it doesnt exists on that
location because the file goodbye.txt it is suposed to be in the same folder
as the executable of my application)

Can someone tell me what can i do

Many thanbks

Author
5 Sep 2006 2:01 PM
Michael D. Ober
When you don't provide a path for the fileinfo class, it uses the
application's current drive and directory for the path.  This has been a
documented invariant since MS-DOS 1.10.

Mike Ober.

Show quote
"eduwushu" <eduwu***@discussions.microsoft.com> wrote in message
news:272296FF-0F4B-45B5-B89D-FAFE5FE7631B@microsoft.com...
> Hi i have an application wich have to retrieve information of files. I
> have
> an openfiledialog on which i cans elect a file and then i retrieve the
> path
> to the file selected on it by the user.I create a FileInfo object with
> that
> path
> Well when i later try to create a new fileinfo object passing to the
> constructor teh relative path of another file it cant find the file
> because
> automatically it puts the path i used before to create another fileinfo
> object at the beginning of my path. For example if i create a first File
> Info
> object this way:
>
> FielInfo info=new FileInfo("C:\Program Files\Folder\hello.txt");
>
> when i try to create this second
>
> FileInfo info=new FileInfo("goodbye.txt");
>
> it throws me an exception saying that the file "C:\Prtogram
> Files\Folder\goodbye.txt" doesnt exists. (Of course it doesnt exists on
> that
> location because the file goodbye.txt it is suposed to be in the same
> folder
> as the executable of my application)
>
> Can someone tell me what can i do
>
> Many thanbks
Author
5 Sep 2006 3:41 PM
eduwushu
but the truth is that when i dont provide a path for the fileinfo class it
takes me the last absolute path i used on the creation of a fileinfo
object!!!!!!!!!
i dont know why this is happening

Show quote
"Michael D. Ober" wrote:

> When you don't provide a path for the fileinfo class, it uses the
> application's current drive and directory for the path.  This has been a
> documented invariant since MS-DOS 1.10.
>
> Mike Ober.
>
> "eduwushu" <eduwu***@discussions.microsoft.com> wrote in message
> news:272296FF-0F4B-45B5-B89D-FAFE5FE7631B@microsoft.com...
> > Hi i have an application wich have to retrieve information of files. I
> > have
> > an openfiledialog on which i cans elect a file and then i retrieve the
> > path
> > to the file selected on it by the user.I create a FileInfo object with
> > that
> > path
> > Well when i later try to create a new fileinfo object passing to the
> > constructor teh relative path of another file it cant find the file
> > because
> > automatically it puts the path i used before to create another fileinfo
> > object at the beginning of my path. For example if i create a first File
> > Info
> > object this way:
> >
> > FielInfo info=new FileInfo("C:\Program Files\Folder\hello.txt");
> >
> > when i try to create this second
> >
> > FileInfo info=new FileInfo("goodbye.txt");
> >
> > it throws me an exception saying that the file "C:\Prtogram
> > Files\Folder\goodbye.txt" doesnt exists. (Of course it doesnt exists on
> > that
> > location because the file goodbye.txt it is suposed to be in the same
> > folder
> > as the executable of my application)
> >
> > Can someone tell me what can i do
> >
> > Many thanbks
>
>
>
Author
5 Sep 2006 6:01 PM
Mattias Sjögren
>but the truth is that when i dont provide a path for the fileinfo class it
>takes me the last absolute path i used on the creation of a fileinfo
>object!!!!!!!!!
>i dont know why this is happening

I'm guessing is because the OpenFileDialog has changed the current
directory (see the FileDialog.RestoreDirectory property).


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

AddThis Social Bookmark Button