0
我越來越想使用SaveFileDialog在下列異常時:異常使用SaveFileDialog
System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process
這裏是我試過的代碼:
private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog { InitialDirectory = @"C:\", Title = "Save text Files", CheckFileExists = true, CheckPathExists = true, DefaultExt = "txt", Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*", FilterIndex = 2, RestoreDirectory = true };
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
String filePath = saveFileDialog1.FileName;
gridView1.Export(DevExpress.XtraPrinting.ExportTarget.Text, filePath);
}
}