Problem with FileInfo class

G

Guest

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
 
M

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.
 
G

Guest

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
 
M

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top