G
Guest
Hello,
Often times, I am interested in the path of a file within the project's root
directory instead of the bin/debug. To get this path, I am using the
following code snippet.
string path = Environment.CurrentDirectory;
string filepath = null;
for (int i = 1; i <= 3; i++) // try going up a few folders (like from
'Debug' or 'Release')
{
filepath = path + @"\" + "book1.xls";
if (File.Exists(filepath)) break;
int index = path.LastIndexOf(@"\", path.Length - 1);
if (index >= 0)
path = path.Substring(0, index);
}
A colleague of mine was making fun of code but then could not think of an
easier way of doing it. Any suggestions?
Thanks,
Dan
Often times, I am interested in the path of a file within the project's root
directory instead of the bin/debug. To get this path, I am using the
following code snippet.
string path = Environment.CurrentDirectory;
string filepath = null;
for (int i = 1; i <= 3; i++) // try going up a few folders (like from
'Debug' or 'Release')
{
filepath = path + @"\" + "book1.xls";
if (File.Exists(filepath)) break;
int index = path.LastIndexOf(@"\", path.Length - 1);
if (index >= 0)
path = path.Substring(0, index);
}
A colleague of mine was making fun of code but then could not think of an
easier way of doing it. Any suggestions?
Thanks,
Dan