private void Lsv_LinkList_MouseDoubleClick(object sender, MouseEventArgs e) { int index = lsv_LinkList.SelectedItems.Count; if (index > 0 && XtraMessageBox.Show("是否打开文件?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ListViewItem item = lsv_LinkList.SelectedItems[0]; string filePath = item.SubItems[1].Text; if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) { WinFormOpenHelper.OpenWinForm(Handle.ToInt32(), "open", filePath, null, null, ShowWindowCommands.SW_NORMAL); } } }
private void DownloadButton_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { object viewRow = view.GetFocusedRow(); if (viewRow != null) { object type = ((DataRowView)viewRow).Row.ItemArray[0]; if ("项目/课题清单".Equals(type)) { XtraMessageBox.Show("此类别文件不可下载", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } folderBrowserDialog1.Description = "选择文件保存路径"; if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { string savePath = folderBrowserDialog1.SelectedPath; object id = ((DataRowView)viewRow).Row.ItemArray[1]; object name = ((DataRowView)viewRow).Row.ItemArray[2]; SqlConnection con = SqlHelper.GetConnect(); string querySQL = $"SELECT at_entity FROM Attachment WHERE at_id='{id}'"; SqlDataAdapter dataAdapter = new SqlDataAdapter(querySQL, con); DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet); Byte[] fileByte = (Byte[])dataSet.Tables[0].Rows[0]["at_entity"]; BinaryWriter bw = new BinaryWriter(File.Open(savePath + "\\" + name, FileMode.OpenOrCreate, FileAccess.Write)); bw.Write(fileByte); bw.Close(); if (XtraMessageBox.Show("文件下载成功。\r\n是否打开文件所在地址", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes) { WinFormOpenHelper.OpenWinForm(0, "open", null, null, savePath, ShowWindowCommands.SW_NORMAL); } } } } }