private void DownloadOpen(string id, string name) { try { FileUploadInfo fileInfo = BLLFactory <FileUpload> .Instance.Download(id); if (fileInfo != null && fileInfo.FileData != null) { string extension = fileInfo.FileExtend.ToLower(); string fileName = fileInfo.FileName; FileUtil.OpenFileInProcess(fileName, fileInfo.FileData); } } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError("下载文件出现错误。具体如下:\r\n" + ex.Message); } }
private void FrmPicturePreview_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(PicturePath)) { this.kpImageViewer1.ImagePath = PicturePath; } if (ImageObj != null) { try { this.kpImageViewer1.Image = ImageObj; } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); } } }
/// <summary> /// 根据列表的书签引用,导出Word文件。 /// </summary> /// <param name="templateFile">模板文件</param> /// <param name="saveFileName">要保存的文件名称</param> /// <param name="dictBookMark">书签键值列表</param> public static void ExportWordWithBookMark(string templateFile, string saveFileName, Dictionary <string, string> dictBookMark) { if (!File.Exists(templateFile)) { MessageDxUtil.ShowWarning(Path.GetFileName(templateFile)); return; } string saveDocFile = FileDialogHelper.Save("保存Word文件", "Word文件(*.doc)|*.doc|All File(*.*)|*.*", saveFileName, "C:\\"); if (!string.IsNullOrEmpty(saveDocFile)) { try { Aspose.Words.Document doc = new Aspose.Words.Document(templateFile); foreach (string name in dictBookMark.Keys) { Aspose.Words.Bookmark bookmark = doc.Range.Bookmarks[name]; if (bookmark != null) { bookmark.Text = dictBookMark[name]; } } doc.Save(saveDocFile); if (MessageDxUtil.ShowYesNoAndTips("保存成功,是否打开文件?") == System.Windows.Forms.DialogResult.Yes) { System.Diagnostics.Process.Start(saveDocFile); } } catch (Exception ex) { LogHelper.Error(ex); MessageDxUtil.ShowError(ex.Message); return; } } }
private void btnView_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(AttachmentDirectory)) { MessageDxUtil.ShowTips("请设置附件的存储目录分类"); return; } if (string.IsNullOrEmpty(m_AttachmentGUID)) { MessageDxUtil.ShowTips("请设置附件组的GUID"); return; } FrmAttachmentGroupView dlg = new FrmAttachmentGroupView(); dlg.AttachmentDirectory = AttachmentDirectory; dlg.AttachmentGUID = AttachmentGUID; dlg.UserId = userId; dlg.OwerId = OwerId; dlg.InitButtonStatus(this.ShowUpload, this.ShowDelete, this.ShowDownload); dlg.OnDataSaved += new EventHandler(dlg_OnDataSaved); dlg.ShowDialog(); }
private void DownloadOrViewFile(string id, string name) { try { FileUploadInfo fileInfo = BLLFactory <FileUpload> .Instance.Download(id); if (fileInfo != null && fileInfo.FileData != null) { string extension = fileInfo.FileExtend.ToLower(); bool isImage = MyHelper.IsImageFile(extension); if (isImage) { FrmPicturePreview frm = new FrmPicturePreview(); Bitmap bitmap = ImageHelper.BitmapFromBytes(fileInfo.FileData); frm.ImageObj = bitmap; frm.ShowDialog(); } else { if (extension.Contains(".pdf")) { FrmPDFView dlg = new FrmPDFView(); dlg.Extension = extension; dlg.Stream = FileUtil.BytesToStream(fileInfo.FileData); dlg.ShowDialog(); } else if (extension.Contains(".xls") || extension.Contains(".xlsx") || extension.Contains(".csv")) { FrmExcelView dlg = new FrmExcelView(); dlg.Extension = extension; dlg.Stream = FileUtil.BytesToStream(fileInfo.FileData); dlg.ShowDialog(); } else if (extension.Contains(".doc") || extension.Contains(".docx") || extension.Contains(".rtf")) { FrmWordView dlg = new FrmWordView(); dlg.Extension = extension; dlg.Stream = FileUtil.BytesToStream(fileInfo.FileData); dlg.ShowDialog(); } else { #region 非图片文件下载到本地 string saveFile = FileDialogHelper.SaveFile(name); if (!string.IsNullOrEmpty(saveFile)) { FileUtil.CreateFile(saveFile, fileInfo.FileData); if (File.Exists(saveFile)) { if (MessageDxUtil.ShowYesNoAndTips("文件下载成功,是否打开文件?") == DialogResult.Yes) { System.Diagnostics.Process.Start(saveFile); } } } #endregion } } } } catch (Exception ex) { LogTextHelper.Error(ex); MessageDxUtil.ShowError("保存文件出现错误。具体如下:\r\n" + ex.Message); } }