//下载 private void repositoryItemButtonEdit2_Click(object sender, EventArgs e) { //获取当前文件的FileDataAttachmentGuid if (gridView2.RowCount > 0) { //得到当前登陆人员所在部门 EmployeeManage EmployeeManage = new EmployeeManage(); string strDept = EmployeeManage.GetEmpDeptByEmpName(SysParams.UserName); string strEmpGuid = EmployeeManage.GetEmpGuIDByEmpName(SysParams.UserName); string strFileGuID = ((DataRowView)(gridView1.GetFocusedRow())).Row["FileGuid"].ToString(); if (rightgroupManage.IsOperateRightByUserID(SysParams.UserID, "FileAllView", "Qry") == false) { //判断是否有下载权限 FileApplyManage FileApplyManage = new FileApplyManage(); if (FileApplyManage.IsDownloadByUserID(strEmpGuid, strDept, strFileGuID) == false) { this.ShowAlertMessage("你没有权限下载此文件!"); return; } // this.ShowAlertMessage("你没有权限下载此文件!"); // return; } string guid = ((DataRowView)(gridView2.GetFocusedRow())).Row["FileDataAttachmentGuid"].ToString(); FileDataManage FileDataManage = new FileDataManage(); DataTable dtl = FileDataManage.GetFileDataAttachmentByAttachmentGuid(guid); if (dtl.Rows.Count > 0) { Byte[] bytes = (Byte[])dtl.Rows[0]["FileContent"]; //先将文件下载到本地 SaveFileDialog SaveFileDialog1 = new SaveFileDialog(); SaveFileDialog1.FileName = dtl.Rows[0]["FileSourceName"].ToString(); SaveFileDialog1.Filter = "All files (*.*)|*.* "; SaveFileDialog1.RestoreDirectory = true; if (SaveFileDialog1.ShowDialog() == DialogResult.OK) { string strfilepath = SaveFileDialog1.FileName; FileStream fs = new FileStream(strfilepath, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(bytes, 0, bytes.Length); fs.Close(); } } } }