WinForm上传文件,下载文件

上传文件:
使用OpenFileDialog控件选择文件,
具体代码示例:

 
private void btnUpLoadPic_Click(object sender, EventArgs e)
        {
            //文件类型过滤
            openFileDialog1.Filter = "图像文件(*.jpg,*.bmp,*.gif)|*.jpg;*.bmp;*.gif";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //得到文件路径全名
                imageFilePath = openFileDialog1.FileName;
                //得到文件名
                currentImageName = imageFilePath.Substring(imageFilePath.LastIndexOf('\') + 1);
                //将选择的图片复制到程序文件夹里(需要IO库)
                //DirectoryInfo directoryInfo=new DirectoryInfo("\Debug\");
                if (new FileInfo(currentImageName).Exists)
                {
                    MessageBox.Show("图片名与图片" + currentImageName + "重名,请修改名称后再次上传");
                }
                else
                {
                    picProduc_add.Image = Image.FromFile(imageFilePath);
                    lblImageName_add.Text = currentImageName;
                }

            }
        }



下载文件:
使用FolderBrowserDialog控件选择文件存放地点:

 //设置浏览文件夹窗口的标题
 folderBrowserDialog1.Description = "选择导出的Excle的存放地点";
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                this.textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
原文地址:https://www.cnblogs.com/xcxcxcxc/p/5541210.html