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


C# HttpResponse.AppendHeader方法代码示例

本文整理汇总了C#中HttpResponse.AppendHeader方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.AppendHeader方法的具体用法?C# HttpResponse.AppendHeader怎么用?C# HttpResponse.AppendHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HttpResponse的用法示例。


在下文中一共展示了HttpResponse.AppendHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DownloadFile

    /// <summary>
    /// �������ؿ�
    /// </summary>
    /// <param name="argResp">����ҳ��</param>
    /// <param name="argFileStream">�ļ���</param>
    /// <param name="strFileName">�ļ���</param>
    public static void DownloadFile(HttpResponse argResp, StringBuilder argFileStream, string strFileName)
    {
        try {
            string strResHeader = "attachment; filename=" + Guid.NewGuid().ToString() + ".csv";
            if (!string.IsNullOrEmpty(strFileName)) {
                strResHeader = "inline; filename=" + strFileName;
            }
            argResp.AppendHeader("Content-Disposition", strResHeader);//attachment˵���Ը������أ�inline˵�����ߴ�
            argResp.ContentType = "application/ms-excel";
            argResp.ContentEncoding = Encoding.GetEncoding("GB2312"); // Encoding.UTF8;//
            argResp.Write(argFileStream);

        } catch (Exception ex) {
            throw ex;
        }
    }
开发者ID:hijoy,项目名称:CPL_ERS,代码行数:22,代码来源:VendorManage.aspx.cs

示例2: 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

示例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

示例4: ReturnImage

 protected void ReturnImage(HttpResponse response, string path, string requestedETag)
 {
     response.Clear();
     var responseETag = LookupEtagFromInput(path);
     if (requestedETag == responseETag)
     {
         response.StatusCode = 304;
         response.StatusDescription = "Not Modified";
         response.AppendHeader("Content-Length", "0");
         response.AppendHeader("Connection", "Close");
         response.End();
     }
     
     response.ContentType = GetContentType(path);
     response.TransmitFile(path);
     response.AppendHeader("Connection", "Keep-Alive");
     // set cache info
     response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);
     response.Cache.VaryByHeaders["If-Modified-Since"] = true;
     response.Cache.VaryByHeaders["If-None-Match"] = true;
     response.Cache.SetLastModified(File.GetLastWriteTime(path));
     response.Cache.SetETag(responseETag);
     response.End();
 }
开发者ID:rosenkolev,项目名称:ASP.NET-Responsive-Images,代码行数:24,代码来源:ImageContentHandler.cs


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