Как я могу получить путь к приложению в консольном приложении .NET?

Другим способом, который я хотел бы сделать это, является привязка идентификатора к свойству CommandParameter кнопки:

<Button Click="Button_Click" CommandParameter="{Binding Path=ID}">View Details</Button>

Затем вы можете получить к нему доступ так же, как в коде:

private void Button_Click(object sender, RoutedEventArgs e)
{
    object ID = ((Button)sender).CommandParameter;
}
875
задан Peter Mortensen 20 November 2013 в 15:40
поделиться

3 ответа

System.Reflection.Assembly.GetExecutingAssembly().Location1

Combine that with System.IO.Path.GetDirectoryName if all you want is the directory.

1As per Mr.Mindor's comment:
System.Reflection.Assembly.GetExecutingAssembly().Location returns where the executing assembly is currently located, which may or may not be where the assembly is located when not executing. In the case of shadow copying assemblies, you will get a path in a temp directory. System.Reflection.Assembly.GetExecutingAssembly().CodeBase will return the 'permanent' path of the assembly.

1134
ответ дан 22 November 2019 в 21:03
поделиться

Возможно, вы захотите сделать это:

System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
27
ответ дан 22 November 2019 в 21:03
поделиться

You can use the following code to get the current application directory.

AppDomain.CurrentDomain.BaseDirectory
392
ответ дан 22 November 2019 в 21:03
поделиться
Другие вопросы по тегам:

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