首页 > 解决方案 > 下载文件并通过 FolderbrowserDialog 选择其位置

问题描述

我尝试下载文件并能够选择其位置在此处输入图像描述

这是我制作的代码

在“目录的使用”中,我定义了一个目录,但我希望能够通过“FolderbrowserDialog”选择它

标签: c#visual-studio

解决方案


请参考此处的示例: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;
        }

推荐阅读