Re: Get path 2 directories up from some known path
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Jul 2005 10:24:38 -0400
Dan,
I'd probably laugh at this too =)
Why not create a custom build action which will copy your file to the
output directory for the build? Since your logic in your program is
probably something similar to that, it's easier to have the build process
set up the output directory correctly instead of putting code in your
program that will change how it acts.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
<DapperDanH@xxxxxxxxxxxxx> wrote in message
news:OSqIoLSkFHA.3756@xxxxxxxxxxxxxxxxxxxxxxx
> 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
>
.
- Follow-Ups:
- Re: Get path 2 directories up from some known path
- From: DapperDanH
- Re: Get path 2 directories up from some known path
- References:
- Get path 2 directories up from some known path
- From: DapperDanH
- Get path 2 directories up from some known path
- Prev by Date: <asp:table...> and PostBack
- Next by Date: ComboBox limitation???
- Previous by thread: Get path 2 directories up from some known path
- Next by thread: Re: Get path 2 directories up from some known path
- Index(es):