c#.net从后台数据库中下载文件

// 下载上传到数据库的文件
            DataTable table = link.SelectDataBase("SELECT TOP 1 FileName, FileType, FileData FROM dbo.TestReport ORDER BY TRID DESC");
            byte[] byte1 = (byte[])table.Rows[0][2];
            //MessageBox.Show(byte1.Length.ToString() + "           " + table.Rows[0]["FileData"].ToString().Trim().Length.ToString());
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.DefaultExt = table.Rows[0]["FileType"].ToString().Trim();
            saveDialog.FileName = table.Rows[0]["FileName"].ToString().Trim();
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                //下载方法一
                File.WriteAllBytes(saveDialog.FileName, byte1);

                //下载方法二
                //Stream stream = File.OpenWrite(saveDialog.FileName);
                //BufferedStream mybystream;
                //mybystream = new BufferedStream(stream);
                //mybystream.Write(byte1, 0, byte1.Length);
                //mybystream.Close();
                //stream.Close();
              
            }

你可能感兴趣的:(c#.net从后台数据库中下载文件)