実行EXEのパスを取得する(´・ω・)ス
インストールするのではないEXE作るのが多いので、
データ保存時に場所指定しないと・・と。
で、サンプルというかメモ( ; ̄ω ̄)ゞ
static string GetAppPath()
{
return System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location);
}
private void button1_Click(object sender, EventArgs e)
{
//C# 実行ファイルのパス取得
MessageBox.Show(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
}
private void button2_Click(object sender, EventArgs e)
{
label1.Text = GetAppPath();
}
private void button3_Click(object sender, EventArgs e)
{
label1.Text = GetAppPath()+"ファイル名.csv";
}
なんかGetAppPath()+ ~というのも変なので
static string GetAppPath()
{
return System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location) + "ああああ.csv";
}
とかでファイル保存を用意もいいかもと。
