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


C# HttpResponse.ClearContent方法代码示例

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


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

示例1: WriteJsonData

    //truyen json data len form
    public static void WriteJsonData(HttpResponse response, Object obj)
    {
        response.Clear();
        response.ClearContent();
        response.ClearHeaders();
        System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer { MaxJsonLength = Int32.MaxValue, RecursionLimit = 100 };

        string output = oSerializer.Serialize(obj);

        response.ContentType = "Application/Json";
        response.Write(output);
        response.End();
    }
开发者ID:Vinhbaba,项目名称:dskfeorfqlhvsea,代码行数:14,代码来源:Default.aspx.cs

示例2: ExportExcel

    /// <summary>
    /// Export excel with HTML format
    /// </summary>
    /// <param name="response">Current page response</param>
    /// <param name="fileName">export file name</param>
    /// <param name="tb">web html table</param>
    public static void ExportExcel(HttpResponse response, string fileName, Table tb)
    {
        try
        {
            response.Clear();
            response.ClearContent();
            response.ClearHeaders();
            response.Buffer = true;
            response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

            response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));

            response.Charset = "utf-8";
            response.ContentEncoding = System.Text.Encoding.UTF8;
            response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble());

            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            tb.RenderControl(oHtmlTextWriter);
            response.Write(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">");
            response.Write(AddExcelStyling());
            string style = @"<style> .text { mso-number-format:\@; } </style>";
            response.Write(style);
            response.Write(oStringWriter.ToString());

            response.End();
        }
        catch (Exception ex)
        {
            Pollinator.Common.Logger.Error("Error occured at " + typeof(ImportExportUltility).Name + " ExportExcel().:", ex);
            response.End();
        }
    }
开发者ID:nazrulcse,项目名称:pollinatror,代码行数:39,代码来源:ImportExportUltility.cs

示例3: ExportToExcel

    public static void ExportToExcel(HttpResponse response, DataSet ds)
    {
        NumberFormatInfo numInfo = Util.GetYankeeNumberFormat();
        DataTable dt = ds.Tables[0];

        response.ClearContent();
        response.ContentEncoding = System.Text.Encoding.UTF8;
        response.ContentType = "application/vnd.ms-excel";
        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        response.Write("\n");
        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                switch (Util.GetMainTypeCode(dr[i].GetType()))
                {
                    case MainTypeCodes.Number:
                        response.Write(tab + ((decimal)dr[i]).ToString("0.00#####", numInfo));
                        break;
                    case MainTypeCodes.DateTime:
                        response.Write(tab + ((DateTime)dr[i]).ToString("yyyy-MM-dd"));
                        break;
                    default:
                        response.Write(tab + dr[i].ToString());
                        break;
                }
                tab = "\t";
            }
            response.Write("\n");
        }
        response.End();
    }
开发者ID:kiquenet,项目名称:B4F,代码行数:39,代码来源:Utility.cs


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