C# • Set Up the Export.

Listing 3. Preparing to execute the export is a simple process. This code demonstrates how the export provider manager initializes the response stream and creates a new HtmlTextWriter to capture the HTML your page generates.

if (Definition != null)
{
   // Get our provider instance
   IExportProvider export = 
      Definition.GetProvider();

   // Set our content type
   Page.Response.ContentType = 
      export.ContentType;

   // See if we need to download as a file
   string downloadAs = export.DownloadAsFileName;
   if (downloadAs.Length > 0)
      Page.Response.AddHeader(
         "Content-Disposition",
         String.Format("attachment;filename={0}", 
         downloadAs));

   // Set the base uri of the export to our base
   export.BaseLocation = 
      ExportHelpers.GetPagePathUri(Page.Request);

   // Override what we are writing text to
   // so we can send it to the export provider
   // in the end
   // ToDo: size appropriately
   mSBExport = new StringBuilder();
   mWriterExport = new 
      System.Web.UI.HtmlTextWriter(new 
      System.IO.StringWriter(mSBExport));

   return mWriterExport;
}

return TrueWriter;