//导出报表
protected void btnExport_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter="word文件|*.doc|Excel文件|*.xlsx|pdf文件|*.pdf|所有文件|*.*";
sfd.Title="请点选路径并输入你要导出的文件名";
sfd.FilterIndex = 1;
sfd.RestoreDirectory = true;
if (sfd.ShowDialog() == DialogResult.OK)
{
string Filename = sfd.FileName;
try
{
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
//File.WriteAllText(Filename, sdf);
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;
DiskOpts.DiskFileName = Filename;
Response.Write("导成成功!");
ReportDoc.ExportOptions.DestinationOptions = DiskOpts;
ReportDoc.Export();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "保存文件出错!");
}
}
else
{
Response.Write("文件导出失败!");
}
}这个异常时处理啊
app.ApartmentState = ApartmentState.STA
在web要这样:
protected void Button1_Click(object sender, EventArgs e)
{
Thread th = new Thread(Test);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
Protected void Test()
{
}