本文整理汇总了C#中HttpResponse.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.Flush方法的具体用法?C# HttpResponse.Flush怎么用?C# HttpResponse.Flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.Flush方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExportExcel
/// <summary>
/// Export excel with binary format using ClosedXml library
/// </summary>
/// <param name="response">Current page response</param>
/// <param name="dt">DataTabe</param>
/// <param name="columnWidths">double array to define the with of column</param>
public static void ExportExcel(HttpResponse response, string fileName, DataTable dt, double[] columnWidths)
{
try
{
int numColumn = columnWidths.Length;
using (XLWorkbook wb = new XLWorkbook())
{
var ws = wb.Worksheets.Add(dt);
using (MemoryStream MyMemoryStream = new MemoryStream())
{
ws.Tables.First().ShowAutoFilter = false;
ws.Tables.First().ShowRowStripes = false;
ws.Tables.First().Theme = XLTableTheme.None;
ws.SheetView.FreezeRows(1);
ws.Row(1).Style.Font.FontColor = XLColor.Black;
ws.Row(1).Style.Font.Bold = true;
ws.Row(1).Style.Alignment.Indent = 1;
ws.Range(1, 1, 1, numColumn).Style.Fill.BackgroundColor = XLColor.LightGreen;
ws.Column(1).Width = columnWidths[0];
if (columnWidths.Length == 18)
{
ws.Column(1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
}
ws.Column(1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
for (int i = 1; i < numColumn; i++)
{
ws.Column(i + 1).Width = columnWidths[i];
ws.Column(i + 1).Style.Alignment.WrapText = true;
ws.Column(i + 1).Style.Alignment.Vertical = XLAlignmentVerticalValues.Top;
}
ws.RangeUsed().Style.Border.InsideBorderColor = XLColor.Black;
ws.RangeUsed().Style.Border.OutsideBorderColor = XLColor.Black;
ws.RangeUsed().Style.Border.InsideBorder = XLBorderStyleValues.Thin;
ws.RangeUsed().Style.Border.OutsideBorder = XLBorderStyleValues.Thin;
wb.SaveAs(MyMemoryStream);
response.Clear();
response.Buffer = true;
response.Charset = "";
response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
MyMemoryStream.WriteTo(response.OutputStream);
response.Flush();
response.End();
}
}
}
catch (Exception ex)
{
Pollinator.Common.Logger.Error("Error occured at " + typeof(ImportExportUltility).Name + " ExportExcel().:", ex);
response.End();
}
}
示例2: DownloadDocument
public static void DownloadDocument(HttpResponse httpResponse, byte[] fileContents, string fileName)
{
try
{
string contentType = "application/octet-stream";
try { contentType = Utilities.GetMimeType(System.IO.Path.GetExtension(fileName)); }
catch (Exception) { }
httpResponse.Clear();
httpResponse.ClearHeaders();
// add cooke so that javascript can detect when file downloaded is done and started if it want's to
// do something (such as letter print page to deselect leter to print)
httpResponse.Cookies["fileDownloaded"].Value = "true";
httpResponse.Cookies["fileDownloaded"].Expires = DateTime.Now.AddHours(3);
httpResponse.ContentType = contentType;
httpResponse.AddHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
httpResponse.OutputStream.Write(fileContents, 0, fileContents.Length);
httpResponse.Flush();
httpResponse.End();
}
catch (System.Web.HttpException ex)
{
// ignore exception where user closed the download box
if (!ex.Message.StartsWith("The remote host closed the connection. The error code is"))
throw;
}
}
示例3: ExportCSV
public static int numFieldOfImportFile = 16; //number column of import file
#endregion Fields
#region Methods
/// <summary>
/// Export data to csv and response directly
/// </summary>
/// <param name="response">Current page response</param>
/// <param name="fileName">export file name</param>
/// <param name="listData">list data to export</param>
public static void ExportCSV(HttpResponse response, string fileName, List<ImportExportFields> listData)
{
//prepare the output stream
response.Clear();
response.Buffer = true;
// response.ContentType = "text/csv";
response.ContentType = "application/octet-stream";//application/vnd.ms-excel";
response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
//response.ContentEncoding = Encoding.Unicode;
response.ContentEncoding = System.Text.Encoding.UTF8;
response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());
response.Write(DataToCsvString(listData));
response.Flush();
response.End();
}