Esempio n. 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
                });
            }
        }