Как получить путь приложения (без app.exe)?

Отключите опцию «Связать с редактором» на панели инструментов Package Explorer.

Package Explorer (значок стрелки влево / вправо, здесь включен)

8
задан ctacke 21 April 2010 в 13:09
поделиться

7 ответов

path = System.IO.Path.GetDirectoryName( path );
10
ответ дан 5 December 2019 в 05:19
поделиться

Проще остальных:

using System.IO;
using System.Reflection;
...
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
3
ответ дан 5 December 2019 в 05:19
поделиться

Application.StartupPath should do that for you.

Update: from you edit I see that you are running on Compact Framework. Then Application.StartupPath will not work. This is the construct that I usually use then:

private static string GetApplicationPath()
{
    return System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
}
18
ответ дан 5 December 2019 в 05:19
поделиться

You can use Path.GetDirectoryName(string) method passing your original path string as parameter for this. What problem are you trying to solve? Maybe you really need something like working directory?

1
ответ дан 5 December 2019 в 05:19
поделиться
Path.GetFileNameWithoutExtension(path);
0
ответ дан 5 December 2019 в 05:19
поделиться

Если это exe-файл, как в вашем случае, используйте:

    // Summary:
    //     Gets the path for the executable file that started the 
    //     application, not including the executable name.    
    Application.StartupPath
0
ответ дан 5 December 2019 в 05:19
поделиться

А как насчет использования объекта FileInfo для извлечения имени каталога?

В Vb.Net:

fi = New FileInfo(System.Reflection.Assembly.GetExecutingAssembly.Location)
path = fi.DirectoryName
0
ответ дан 5 December 2019 в 05:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: