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

第一种 

 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().ToArray();

        if (selectedFolders.Length > 0)
        {
               string selectedFolder = selectedFolders[0];
        }
  }

 

WPF调用选择文件夹保存文件_第1张图片

第二种: 

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

 

WPF调用选择文件夹保存文件_第2张图片

 

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

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

 

 WPF调用选择文件夹保存文件_第3张图片

 

你可能感兴趣的:(C#,WPF)