下载文件并通过FolderbrowserDialog选择其位置

时间:2018-12-23 18:24:14

标签: c# visual-studio

我尝试下载文件并能够选择其位置enter image description here

这是我编写的代码

在“使用目录”中,这是我定义目录的位置,但是我希望能够通过“ FolderbrowserDialog”进行选择

1 个答案:

答案 0 :(得分:0)

请在此处参考示例:https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.folderbrowserdialog?view=netframework-4.7.2

特别是:

if(result == DialogResult.OK) 
    {
        openFileName = openFileDialog1.FileName;
        try
        {
            // Output the requested file in richTextBox1.
            Stream s = openFileDialog1.OpenFile();
            richTextBox1.LoadFile(s, RichTextBoxStreamType.RichText);
            s.Close();    

            fileOpened = true;

        } 
        catch(Exception exp)
        {
            MessageBox.Show("An error occurred while attempting to load the file. The error is:" 
                            + System.Environment.NewLine + exp.ToString() + System.Environment.NewLine);
            fileOpened = false;
        }