Удержание выбранного файла для дальнейшего использования - PullRequest
0 голосов
/ 22 марта 2020

Я нахожусь в C# Windows Настольном приложении и хочу знать, как я могу хранить файл, как видно при каждом выборе файла для загрузки. Я могу открыть файл для выбора, но когда я «открываю» файл, ничего не происходит. Вот что у меня есть для моей кнопки:

private void button1_Click(object sender, EventArgs e)
{
    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();
            }                    
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...