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


C# HttpResponse.Clear方法代码示例

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


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

示例1: DataTableToExcel

        /// <summary>
        /// Datatable数据填充如excel
        /// </summary>
        /// <param name="filename">excel文件名</param>
        /// <param name="dt"> 数据源</param>
        /// <param name="Response"> response响应</param>
        ///  <param name="headerStr"> 表头标题</param>
        public static void DataTableToExcel(string filename, DataTable dt, string sheetname, HttpResponse Response, string headerStr)
        {
            MemoryStream ms = StreamData(dt, sheetname, headerStr) as MemoryStream; //as MemoryStream  as用作转换,此处可以省略
            try
            {

                Response.Clear();
                Response.ContentType = "application/vnd.ms-excel";
                Response.ContentEncoding = Encoding.UTF8;
                Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename + ".xls"));
                Response.AddHeader("content-length", ms.Length.ToString());
                Byte[] data = ms.ToArray(); //文件写入采用二进制流的方式。所以此处要转换为字节数组
                Response.BinaryWrite(data);
            }
            catch
            {
                Response.Clear();
                Response.ClearHeaders();
                Response.Write("<script language=javascript>alert( '导出Excel错误'); </script>");
            }
            Response.Flush();
            Response.Close();
            Response.End();
            ms = null;
        }
开发者ID:mildrock,项目名称:wechat,代码行数:32,代码来源:NPOIHelper.cs

示例2: SendPosterToBrowser

        public static void SendPosterToBrowser( PosterBuilder.Builder pb, HttpResponse resp, string posterFilename, PosterBuilder.ImgFormat.SupportedTypes outputFormat)
        {
            string filename = BuildFilename(posterFilename, outputFormat);

            resp.Clear();
            // Ensure caching is off naturally
            resp.CacheControl = "no-cache";

            resp.ContentType = PosterBuilder.ImgFormat.ToMimeType(outputFormat);
            resp.AddHeader("Content-Disposition", "attachment;filename=" + filename);

            // Call our image with our amendments and have it save to the response so we can send it back
            Bitmap bmp = pb.Render();

            // Have the Poster build our new image and save the result to the outgoing response
            // ... have to do all this with MemoryStreams as PNG doesn't like being saved directly to HttpResponse.OutputStream
            // ... may as well do the same for all image types and be consistent
            using (Bitmap bitmap = pb.Render()) {

                using (MemoryStream ms = new MemoryStream()) {
                    ImageFormat outFmt = PosterBuilder.ImgFormat.ToImageFormat(outputFormat);

                    bmp.Save(ms, outFmt);

                    ms.WriteTo(resp.OutputStream);
                } // using ms

            } // using pb

            // And of course, clear up after ourselves
            pb.Dispose();
            resp.End();
        }
开发者ID:toepoke,项目名称:PosterBuilder,代码行数:33,代码来源:Helpers.cs

示例3: PrepareResponse

 public void PrepareResponse(HttpResponse httpResponse)
 {
     httpResponse.Clear();
     httpResponse.ContentType = "text/tab-separated-values";
     httpResponse.AddHeader("content-disposition", "attachment; filename=\"" + "export" + ".tsv\"");
     httpResponse.BufferOutput = false;
 }
开发者ID:T-o-m-a-s-z,项目名称:MVCGrid.Net,代码行数:7,代码来源:TabDelimitedRenderingEngine.cs

示例4: ExportToCSV

        public void ExportToCSV(DataTable dataTable, HttpResponse response)
        {
            response.Clear();
            response.Buffer = true;
            response.AddHeader("content-disposition",
                "attachment;filename=DataTable.csv");
            response.Charset = "";
            response.ContentType = "application/text";

            StringBuilder sb = new StringBuilder();
            for (int k = 0; k < dataTable.Columns.Count; k++)
            {
                //add separator
                sb.Append(dataTable.Columns[k].ColumnName + ',');
            }
            //append new line
            sb.Append("\r\n");
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                for (int k = 0; k < dataTable.Columns.Count; k++)
                {
                    //add separator
                    sb.Append(dataTable.Rows[i][k].ToString().Replace(",", ";") + ',');
                }
                //append new line
                sb.Append("\r\n");
            }
            response.Output.Write(sb.ToString());
            response.Flush();
            response.End();
        }
开发者ID:rudolfcruz,项目名称:Reports,代码行数:31,代码来源:GenReportes.cs

示例5: Real

        private void Real(HttpResponse response, HttpRequest request)
        {
            if (File.Exists(request.PhysicalPath))
            {
                FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
                response.Clear();
                response.AddHeader("Content-Disposition", "filename=" + file.Name);
                response.AddHeader("Content-Length", file.Length.ToString());
                string fileExtension = file.Extension.ToLower();
                switch (fileExtension)
                {
                   
                    case ".jpg":
                        response.ContentType = "image/jpeg";
                        break;
                    case ".gif":
                        response.ContentType = "image/gif";
                        break;
                    case ".png":
                        response.ContentType = "image/png";
                        break;
                    default:
                        response.ContentType = "application/octet-stream";
                        break;
                }

                response.WriteFile(file.FullName);
                response.End();
            }
            else
            {
                response.Write("File Not Exists");
            }
        }
开发者ID:Xiaoyuyexi,项目名称:LMS,代码行数:34,代码来源:HttpImg.cs

示例6: Real

        private void Real(HttpResponse response, HttpRequest request)
        {
            if (File.Exists(request.PhysicalPath))
            {
                FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
                response.Clear();
                response.AddHeader("Content-Disposition", "filename=" + file.Name);
                response.AddHeader("Content-Length", file.Length.ToString());
                string fileExtension = file.Extension.ToLower();
                switch (fileExtension)
                {
                    case ".mp3":
                        response.ContentType = "audio/mpeg3";
                        break;
                    case ".mpeg":
                        response.ContentType = "video/mpeg";
                        break;
                    case ".jpg":
                        response.ContentType = "image/jpeg";
                        break;
                    case ".bmp":
                        response.ContentType = "image/bmp";
                        break;
                    case ".gif":
                        response.ContentType = "image/gif";
                        break;
                    case ".doc":
                        response.ContentType = "application/msword";
                        break;
                    case ".css":
                        response.ContentType = "text/css";
                        break;
                    case ".html":
                        response.ContentType = "text/html";
                        break;
                    case ".htm":
                        response.ContentType = "text/html";
                        break;
                    case ".swf":
                        response.ContentType = "application/x-shockwave-flash";
                        break;
                    case ".exe":
                        response.ContentType = "application/octet-stream";
                        break;
                    case ".inf":
                        response.ContentType = "application/x-texinfo";
                        break;
                    default:
                        response.ContentType = "application/octet-stream";
                        break;
                }

                response.WriteFile(file.FullName);
                response.End();
            }
            else
            {
                response.Write("File Not Exists");
            }
        }
开发者ID:Xiaoyuyexi,项目名称:LMS,代码行数:60,代码来源:HttpNotFound.cs

示例7: GetByRouteName

        /// <summary>
        /// Gets the URL represented by the named route.
        /// </summary>
        /// <param name="response">The HTTP context response.</param>
        /// <param name="routeName">The route name.</param>
        /// <returns>The generated URL.</returns>
        public static string GetByRouteName(HttpResponse response, string routeName)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            if (String.IsNullOrEmpty(routeName))
            {
                throw new ArgumentNullException("routeName");
            }

            VirtualPathData pathData = RouteTable.Routes.GetVirtualPath(null, routeName, new RouteValueDictionary());

            if (pathData != null && !String.IsNullOrEmpty(pathData.VirtualPath))
            {
                return pathData.VirtualPath;
            }

            response.Clear();
            response.StatusCode = (int) HttpStatusCode.NotFound;
            response.StatusDescription = String.Format(CultureInfo.InvariantCulture, Resources.Global.InvalidNamedRoute, routeName);

            return null;
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:31,代码来源:ProxyUrlHelper.cs

示例8: ExportToExcelFile

        /// <summary>
        /// Exporta la información a Excel.
        /// </summary>
        /// <param name="response">HttpResponse actual.</param>
        /// <param name="data">Datos a exportar.</param>
        /// <param name="nombreArchivo">Nombre del archivo Excel</param>
        public static void ExportToExcelFile(HttpResponse response, DataView data, string nombreArchivo)
        {
            var dg = new DataGrid { DataSource = data };
            dg.DataBind();

            response.Clear();
            response.Buffer = true;

            //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
            response.AddHeader("Content-Disposition", "filename=" + nombreArchivo);
            response.ContentType = "application/vnd.ms-excel";
            response.Charset = "UTF-8";
            response.ContentEncoding = System.Text.Encoding.Default;

            var stringWriter = new StringWriter();
            var htmlWriter = new HtmlTextWriter(stringWriter);
            dg.RenderControl(htmlWriter);

            response.Write(stringWriter.ToString());
            //resp.Flush();
            try
            {
                response.End();
            }
            catch (Exception ex)
            {
                ISException.RegisterExcepcion(ex);
                throw ex;
            }
        }
开发者ID:preguntoncojonero,项目名称:test,代码行数:36,代码来源:ISExcel.cs

示例9: ExportToExcel

        public void ExportToExcel(DataTable dataTable, HttpResponse response)
        {
            // Create a dummy GridView
            GridView GridView1 = new GridView();
            GridView1.AllowPaging = false;
            GridView1.DataSource = dataTable;
            GridView1.DataBind();
            response.Clear();
            response.Buffer = true;
            response.AddHeader("content-disposition", "attachment;filename=DataTable.xls");
            response.Charset = "";
            response.ContentType = "application/vnd.ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            for (int i = 0; (i
                        <= (GridView1.Rows.Count - 1)); i++)
            {
                // Apply text style to each Row
                GridView1.Rows[i].Attributes.Add("class", "textmode");
            }

            GridView1.RenderControl(hw);
            // style to format numbers to string
            string style = "<style> .textmode{mso-number-format:\\@;}</style>";
            response.Write(style);
            response.Output.Write(sw.ToString());
            response.Flush();
            response.End();
        }
开发者ID:rudolfcruz,项目名称:Reports,代码行数:29,代码来源:GenReportes.cs

示例10: WriteError

 private static void WriteError(string error, HttpResponse response)
 {
     response.Clear();
     response.Status = "Internal Server Error";
     response.StatusCode = 500;
     response.Output.WriteLine(error);
 }
开发者ID:KostovMartin,项目名称:mKWays,代码行数:7,代码来源:AjaxHandler.cs

示例11: SavePdf

        public void SavePdf( HttpResponse response, string downloadfilename )
        {
            response.Clear();
            response.ContentType = "application/x-pdf";
            response.AddHeader("content-disposition", string.Format("attachment; filename={0}",downloadfilename));

            SavePdf(response.OutputStream);
        }
开发者ID:Dnigor,项目名称:mycnew,代码行数:8,代码来源:PDFGenerator.cs

示例12: RedirectPermanent

		static void RedirectPermanent(HttpResponse response, string destination)
		{
			response.Clear();
			response.Status = "301 Moved Permanently";
			response.AddHeader("Location", destination);
			response.Flush();
			response.End();
		}
开发者ID:andy4711,项目名称:n2cms,代码行数:8,代码来源:RequestLifeCycleHandler.cs

示例13: CloseIt

 public static void CloseIt(HttpResponse response)
 {
     response.Clear();
     response.Write("<script type=\"text/javascript\">");
     response.Write("window.close();");
     response.Write("</script>");
     response.End();
 }
开发者ID:0anion0,项目名称:IBN,代码行数:8,代码来源:CHelper.cs

示例14: PermanentRedirect

 private static void PermanentRedirect(HttpResponse response, string location)
 {
     response.Clear();
     response.StatusCode = (int)HttpStatusCode.MovedPermanently;
     response.StatusDescription = "Moved Permanently";
     response.AddHeader("Location", location);
     response.End();
 }
开发者ID:jtpatil,项目名称:webstack,代码行数:8,代码来源:RoutingModule.cs

示例15: ShowDownloadToolFile

        public static bool ShowDownloadToolFile(HttpResponse httpResponse, NameValueCollection queryString, CommonUtils.AppSettingKey settingKey, out Exception message)
        {
            try
            {
                string fileName = queryString["DownloadToolFile"];

                if (string.IsNullOrEmpty(fileName))
                {
                    message = new Exception("Query string 'DownloadToolFile' missing from url.");
                    return false;
                }

                if (!File.Exists(fileName))
                {
                    message = new FileNotFoundException(string.Format(@"Failed to find file '{0}'.
                                                    Please ask your administrator to check whether the folder exists.", fileName));
                    return false;
                }

                httpResponse.Clear();
                httpResponse.ClearContent();

                //Response.OutputStream.f
                httpResponse.BufferOutput = true;
                httpResponse.ContentType = "application/unknown";
                httpResponse.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", Path.GetFileName(fileName)));
                byte[] fileContent = File.ReadAllBytes(fileName);

                BinaryWriter binaryWriter = new BinaryWriter(httpResponse.OutputStream);
                binaryWriter.Write(fileContent, 0, fileContent.Length);
                binaryWriter.Flush();
                binaryWriter.Close();

                var dirName = Path.GetDirectoryName(fileName);

                if (dirName != null)
                {
                    //Delete any files that are older than 1 hour
                    Directory.GetFiles(dirName)
                        .Select(f => new FileInfo(f))
                        .Where(f => f.CreationTime < DateTime.Now.AddHours(-1))
                        .ToList()
                        .ForEach(f => f.Delete());
                }
            }
            catch (Exception ex)
            {
                message = ex;
                return false;
            }

            message = null;
            return true;
        }
开发者ID:barrett2474,项目名称:CMS2,代码行数:54,代码来源:Common.cs


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