WPF调用选择文件夹保存文件

mac2025-01-22  69

第一种 

Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Core.FileDialog fileDialog = app.get_FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFolderPicker); fileDialog.InitialFileName = ""; //something you want int nres = fileDialog.Show(); if (nres == -1) //ok { Microsoft.Office.Core.FileDialogSelectedItems selectedItems = fileDialog.SelectedItems; string[] selectedFolders = selectedItems.Cast<string>().ToArray(); if (selectedFolders.Length > 0) { string selectedFolder = selectedFolders[0]; } }

 

第二种: 

System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog(); if (folderBrowserDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string outDir = folderBrowserDialog.SelectedPath; }

 

 

第三种:自定义命名保存文件

var saveFileDialog1 = new System.Windows.Forms.SaveFileDialog { Filter = "Excel 工作簿|*.xlsx|Excel 97-2003 工作簿|*.xls", Title = "导出到" }; saveFileDialog2.ShowDialog();

 

 

 

最新回复(0)