当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponse.Flush方法代码示例

本文整理汇总了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();
        }
    }
开发者ID:nazrulcse,项目名称:pollinatror,代码行数:66,代码来源:ImportExportUltility.cs

示例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;
        }
    }
开发者ID:mcep,项目名称:Mediclinic,代码行数:30,代码来源:Letter.cs

示例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();
    }
开发者ID:nazrulcse,项目名称:pollinatror,代码行数:29,代码来源:ImportExportUltility.cs


注:本文中的HttpResponse.Flush方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。