|
-
March 12th, 2003, 11:39 PM
#1
Determining if file exists
hi all. i am currently writing a simple program. in my program, before the form loads, i would need to determine if a file named "abc.mdb" exists in the current directory of the running program. so below is what i did:
Code:
private void MainFrm_Load(object sender, System.EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
FileInfo fi = new FileInfo(curDir+"\\Abc.Mdb");
string fp = fi.FullName;
if(fi.Exists == false)
{
MessageBox.Show("System file Abc.Mdb is not found.", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
else
{
}
}
The problem is that EVEN the file EXISTS in the current directory fi.Exists is still false. Can anyone help? Thanks.
-
March 13th, 2003, 01:33 PM
#2
what have happend is
string curDir = Directory.GetCurrentDirectory();
when you do this in debug mode then it will return the current directory as debug directory,
so what i generally do is
FileInfo fi = new FileInfo(curDir+"\\..\\..\\abc.mdb");
string fp = fi.FullName;
so it goes back in previous directory and then fetches.. or if you have particular path then you can type there.
note in my case Exists returns true..
if file is found in path and should also be true in ur case if actually file is found.
Paresh
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|