Загрузка...

Как с FileDialog сохранить путь в string переменную

Тема в разделе C# создана пользователем Minin_inactive4471240 10 фев 2022. 135 просмотров

  1. Minin_inactive4471240
    Minin_inactive4471240 Автор темы 10 фев 2022 3 5 сен 2021

    private void button2_Click(object sender, EventArgs e)
    {


    var dialog = new OpenFileDialog();
    if (dialog.ShowDialog() != DialogResult.OK)
    {
    string path = dialog.FileName;
    MessageBox.Show(path);
    return;

    }

    }
     
  2. утин
    утин 10 фев 2022 5 13 ноя 2019
    [IMG] я бы сделал что-то типо такого
     
  3. Yotic
    Yotic 11 фев 2022 Ебашу на C# всё что захотите(Разноцветное) 43 13 янв 2021
    C#
    var fileContent = string.Empty;
    var filePath = string.Empty;

    using (OpenFileDialog openFileDialog = new OpenFileDialog())
    {
    openFileDialog.InitialDirectory = "c:\\";
    openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    openFileDialog.FilterIndex = 2;
    openFileDialog.RestoreDirectory = true;

    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
    //Get the path of specified file
    filePath = openFileDialog.FileName;

    //Read the contents of the file into a stream
    var fileStream = openFileDialog.OpenFile();

    using (StreamReader reader = new StreamReader(fileStream))
    {
    fileContent = reader.ReadToEnd();
    }
    }
    }
     
    1. утин
      Yotic, а нахуя ему собственно данные с txt в переменной?
Загрузка...
Top