我的是Web中调用水晶报表。已经做成功导出文件。但是有个问题就是我如何把文件生成到客户端的机器中而不是服务器。
具体代码如下:此代码只实现导出文件,但是没能实现在客户端生成文件。需要在此基础上修改,还是要重新写。最好有实例。先谢过了。
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
CRS.ReportDocument.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
CRS.ReportDocument.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
DiskOpts.DiskFileName = "d:\\Report.pdf";
strCheckFileName = strCheckFileName + ".pdf";
CRS.ReportDocument.ExportOptions.DestinationOptions = DiskOpts;
CRS.ReportDocument.Export();

解决方案 »

  1.   

    跳出窗口实现保存会被广告拦截软件直接拦截掉
    用Response.BinaryWrite写文件流  实现了此功能
    从注册表读取文件的ContentType 识别文件格式。
            /// <summary>
            /// 下载文件
            /// </summary>
            /// <param name="filename">文件物理地址</param>
            protected void DownloadFile(string filename)
            {
                string saveFileName = "test.xls";
                int intStart = filename.LastIndexOf("\\") + 1;
                saveFileName = filename.Substring(intStart, filename.Length - intStart);            System.IO.FileInfo fi = new System.IO.FileInfo(filename);
                string fileextname = fi.Extension;
                string DEFAULT_CONTENT_TYPE = "application/unknown";
                RegistryKey regkey, fileextkey;
                string filecontenttype;
                try
                {
                    regkey = Registry.ClassesRoot;
                    fileextkey = regkey.OpenSubKey(fileextname);
                    filecontenttype = fileextkey.GetValue("Content Type", DEFAULT_CONTENT_TYPE).ToString();
                }
                catch
                {
                    filecontenttype = DEFAULT_CONTENT_TYPE;
                }            Response.Clear();
                Response.Charset = "utf-8";
                Response.Buffer = true;
                this.EnableViewState = false;
                Response.ContentEncoding = System.Text.Encoding.UTF8;            Response.AppendHeader("Content-Disposition", "attachment;filename=" + saveFileName);
                Response.ContentType = filecontenttype;            Response.WriteFile(filename);
                Response.Flush();
                Response.Close();
                Response.End();
            }
      

  2.   

    导出文件到服务器端,再输出实现下载
     private CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts;
     DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
    oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
    oRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
    DiskOpts.DiskFileName = Server.MapPath("\WebApplication1\Output.pdf");                    
     oRpt.ExportOptions.DestinationOptions = DiskOpts;
     oRpt.Export();   Response.ClearHeaders();
                Response.Buffer = false;
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(name, System.Text.Encoding.UTF8));
                Response.WriteFile(filename);
                Response.Flush();
                Response.End();