Ejemplo n.º 1
0
        public static FileStreamResult ToRtfResult(this DataDynamics.ActiveReports.Document.Document reportDocument, string name)
        {
            // Do not close or dispose MemoryStream as the FileStreamResult disposes it after use
            var memoryStream = new MemoryStream();

            using (var exported = new RtfExport())
            {
                exported.Export(reportDocument, memoryStream);

                memoryStream.Flush();
                memoryStream.Seek(0, SeekOrigin.Begin);

                var fileStreamResult = new FileStreamResult(memoryStream, "application/msword");

                fileStreamResult.FileDownloadName = string.Format("{0}.doc", name);

                return(fileStreamResult);
            }
        }
 public override void WriteToStream(Type type, object value, Stream writeStream, HttpContent content)
 {
     using (var writer = new StreamWriter(writeStream)) {
         var report = value as SectionReport;
         if (report != null)
         {
             var memStream = new MemoryStream();
             var rtfExport = new RtfExport();
             rtfExport.Export(report.Document, memStream);
             memStream.Position = 0;
             writeStream.Write(memStream.ToArray(), 0, (int)memStream.Length);
             content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline")
             {
                 FileName = report.Name + ".rtf"
             };
         }
         else
         {
             throw new InvalidOperationException("Cannot serialize type");
         }
     }
 }