示例#1
0
        // Set ShowSaveFileDialog
        public static ShowSaveFileDialogRe ShowSaveFileDialog(string tempFilename, FileInfo2 defaultFilename)
        {
            try
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.Filter           = "Excel Files|*.xlsx";
                saveFileDialog1.FilterIndex      = 1;
                saveFileDialog1.RestoreDirectory = true;
                saveFileDialog1.OverwritePrompt  = true;

                // 預設檔案名稱
                if (defaultFilename != null)
                {
                    saveFileDialog1.FileName         = defaultFilename.getGetFileNameWithoutExtension();
                    saveFileDialog1.InitialDirectory = defaultFilename.getDirectoryName();
                    saveFileDialog1.RestoreDirectory = true;
                }

                DialogResult dr = saveFileDialog1.ShowDialog();
                if (dr == DialogResult.OK && saveFileDialog1.FileName != "")
                {
                    File.Copy(tempFilename, saveFileDialog1.FileName, true);
                    // 回傳資訊
                    return(new ShowSaveFileDialogRe
                    {
                        dialogResult = dr,
                        msg = saveFileDialog1.FileName
                    });
                }
                // 回傳資訊
                return(new ShowSaveFileDialogRe
                {
                    dialogResult = dr,
                    msg = saveFileDialog1.FileName
                });
            }
            catch (IOException ex)
            {
                // 回傳資訊
                return(new ShowSaveFileDialogRe
                {
                    dialogResult = DialogResult.Abort,
                    msg = ex.Message
                });
            }
        }
示例#2
0
 // BackgroundWorker 執行完成
 private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Result != null)
     {
         string finishedFileName = null;
         try
         {
             if (showSaveAsDialogBox)
             {
                 RunShowSaveFileDialogRe(e.Result.ToString());
             }
             else
             {
                 if (saveAsFile.isDirectoryExists())
                 {
                     finishedFileName = bwGenExcelArgs.outputFile;
                     File.Copy(e.Result.ToString(), finishedFileName, true);
                     SetOutputExcelFileName(finishedFileName);
                     openExcel.Visible = true;
                 }
                 else
                 {
                     // 指定目錄不存在要跳出MessageBox
                     Fun.showMessageBox(
                         String.Format("\"{0}\" destination directory does not exist.",
                                       saveAsFile.getDirectoryName()), "SaveAs error");
                     RunShowSaveFileDialogRe(e.Result.ToString());
                 }
             }
         }
         catch (IOException ex)
         {
             Fun.showMessageBox(
                 string.Format("{0}",
                               ex.Message), "SaveAs error");
         }
     }
 }