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


C# HttpResponse.Flush方法代码示例

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


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

示例1: GetImage

        public void GetImage(HttpResponse reponse, int id)
        {
            using (SqlConnection connection = new SqlConnection("Data Source=DESKTOP-5A9RHHB;Initial Catalog=EcommerceSimplifie; Integrated Security=True"))
            {
                //try
                //{
                SqlCommand command = new SqlCommand("select Picture.PictureBinary, Picture.MimeType from Picture inner join Product_Picture_Mapping on Picture.Id = Product_Picture_Mapping.PictureId where ProductId = @id and DisplayOrder = 1;");
                command.Connection = connection;
                command.Parameters.Add(new SqlParameter("@id", id));

                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {

                    //type de l'image
                    string typeMime = reader.GetString(1);
                    reponse.ContentType = (string.IsNullOrEmpty(typeMime)) ? "image/jpeg" : typeMime;

                    //mise en cache
                    reponse.Cache.SetCacheability(HttpCacheability.Public);

                    int indexDepart = 0;
                    int tailleBuffer = 1024;
                    long nombreOctets = 0;
                    Byte[] flux = new Byte[1024];

                    nombreOctets = reader.GetBytes(0, indexDepart, flux, 0, tailleBuffer);

                    while (nombreOctets == tailleBuffer)
                    {
                        reponse.BinaryWrite(flux);
                        reponse.Flush();
                        indexDepart += tailleBuffer;
                        nombreOctets = reader.GetBytes(0, indexDepart, flux, 0, tailleBuffer);
                    }
                    if (nombreOctets > 0)
                    {
                        reponse.BinaryWrite(flux);
                        reponse.Flush();
                    }
                    reponse.End();

                }
                //catch(Exception)
                //{
                //    throw new Exception("Pas d'image disponible.");
                //}
                //}
            }
        }
开发者ID:boule46,项目名称:activite_git,代码行数:53,代码来源:HandlerImage.cs

示例2: ToExcel

        public static void ToExcel(HttpResponse Response,DataTable dt , string fileName)
        {
            Response.ContentType = "application/csv";
            Response.Charset = "";
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
            Response.ContentEncoding = Encoding.Unicode;
            Response.BinaryWrite(Encoding.Unicode.GetPreamble());

            try
            {
                StringBuilder sb = new StringBuilder();

                //Add Header
                for (int count = 0; count < dt.Columns.Count - 1; count++)
                {
                    if (dt.Columns[count].ColumnName != null)
                        sb.Append(dt.Columns[count].ColumnName);
                    sb.Append("\t");
                }
                Response.Write(sb.ToString() + "\n");
                Response.Flush();

                //Append Data
                int index = 0;
                while (dt.Rows.Count >= index + 1)
                {
                    sb = new StringBuilder();

                    for (int col = 0; col < dt.Columns.Count -1; col++)
                    {
                        if (dt.Rows[index][col] != null)
                            //sb.Append(dt.Rows[index][col].ToString().Replace(",", " "));
                            sb.Append(dt.Rows[index][col].ToString());
                        sb.Append("\t");
                    }

                    Response.Write(sb.ToString() + "\n");
                    Response.Flush();
                    index = index + 1;
                }

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            dt.Dispose();
            Response.End();
        }
开发者ID:thanhphat,项目名称:ibookstop,代码行数:50,代码来源:Table2Excel.cs

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

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

示例6: ToString

        /// <summary>
        /// Renders a partial view to a string in the specified context.
        /// </summary>
        /// <param name="partialViewContext">The partial view context.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="cookies">Any cookies that were captures as part of the response.</param>
        /// <returns>The view rendered as a string.</returns>
        public static string ToString(PartialViewContext partialViewContext, object viewModel, out HttpCookieCollection cookies)
        {
            string viewName = partialViewContext.ViewName;

            using (var writer = new StringWriter())
            {
                var httpRequest = new HttpRequest("", "http://www.example.com", "");
                var httpResponse = new HttpResponse(writer);

                // There are still dependencies on HttpContext.Currrent in the ASP.NET (MVC) framework, eg., AntiForgeryRequestToken (as of ASP.NET MVC 4).
                var httpContext = new HttpContext(httpRequest, httpResponse) { User = partialViewContext.User };
                System.Web.HttpContext.Current = httpContext;

                var controllerContext = CreateControllerContext(httpContext);

                var viewEngineResult = ViewEngines.Engines.FindPartialView(controllerContext, viewName);
                if (viewEngineResult == null)
                {
                    string message = "The partial view was not found.";
                    throw new ArgumentException(message, viewName);
                }

                var view = viewEngineResult.View;
                if (view == null)
                {
                    var locations = new StringBuilder();
                    foreach (string searchedLocation in viewEngineResult.SearchedLocations)
                    {
                        locations.AppendLine();
                        locations.Append(searchedLocation);
                    }

                    throw new ArgumentException("The partial view was not found. The following locations were searched: " + locations, viewName);
                }

                try
                {
                    var viewData = new ViewDataDictionary(viewModel);
                    var tempData = new TempDataDictionary();

                    var viewContext = new ViewContextStub(controllerContext, view, viewData, tempData, writer)
                    {
                        ClientValidationEnabled = partialViewContext.ClientValidationEnabled,
                        UnobtrusiveJavaScriptEnabled = partialViewContext.UnobtrusiveJavaScriptEnabled
                    };

                    view.Render(viewContext, httpResponse.Output);
                    cookies = controllerContext.HttpContext.Response.Cookies;

                    httpResponse.Flush();
                }
                finally
                {
                    viewEngineResult.ViewEngine.ReleaseView(controllerContext, view);
                }

                return writer.ToString();
            }
        }
开发者ID:marcusoftnet,项目名称:crowbar,代码行数:66,代码来源:CrowbarController.cs

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

示例8: ToExcel

        public static void ToExcel(DataSet dsInput, string filename, HttpResponse response)
        {
            var excelXml = GetExcelXml(dsInput, filename);
            response.Clear();
            response.AppendHeader("Content-Type", "application/vnd.ms-excel");
            response.AppendHeader("Content-Disposition", "attachment; filename=\"" + HttpContext.Current.Server.UrlEncode(filename) + "\"");

            response.Write(excelXml);
            response.Flush();
            response.End();
        }
开发者ID:mccj,项目名称:FOMS,代码行数:11,代码来源:ExcelHelper.cs

示例9: RenderToResponseStream

 private static void RenderToResponseStream(HttpResponse response, XmlBaseController baseController)
 {
     // save script timeout
     var scriptTimeOut = HttpContext.Current.Server.ScriptTimeout;
     // temporarily set script timeout to large value ( this value is only applicable when application is not running in Debug mode )
     HttpContext.Current.Server.ScriptTimeout = int.MaxValue;
     response.ContentType = baseController.ContentType;
     response.AppendHeader("content-disposition", "inline; filename=" + baseController.FileName);
     baseController.Render(response.OutputStream);
     response.Flush();
     // reset script timeout
     HttpContext.Current.Server.ScriptTimeout = scriptTimeOut;
 }
开发者ID:DNNCommunity,项目名称:DNN.XML,代码行数:13,代码来源:download.ashx.cs

示例10: DownloadLatexFromEstimate

 /// <summary>
 /// Downloads the latex from estimate.
 /// </summary>
 /// <param name="projectId">The project id.</param>
 /// <param name="maxPriority">The max priority.</param>
 /// <param name="response">The response.</param>
 public void DownloadLatexFromEstimate(int? projectId
     , int? maxPriority
     , HttpResponse response)
 {
     response.Clear();
     response.AddHeader
         ("Content-Disposition"
         , "attachment;filename=estimate.tex");
     response.ContentType = "application/x-latex";
     response.Write(GetLatexFromEstimate
         (projectId, maxPriority));
     response.Flush();
     response.End();
 }
开发者ID:uncas,项目名称:hibes,代码行数:20,代码来源:LatexHelpers.cs

示例11: ToString

        /// <summary>
        /// Renders a partial view to a string in the specified context.
        /// </summary>
        /// <param name="crowbarViewContext">The view context.</param>
        /// <param name="viewModel">The view model.</param>
        /// <param name="cookies">Any cookies that were captures as part of the response.</param>
        /// <returns>The view rendered as a string.</returns>
        public static string ToString(CrowbarViewContext crowbarViewContext, object viewModel, out HttpCookieCollection cookies)
        {
            string viewName = crowbarViewContext.ViewName;

            using (var writer = new StringWriter())
            {
                var httpRequest = new HttpRequest("", "http://www.example.com", "");
                var httpResponse = new HttpResponse(writer);

                var controllerContext = CreateControllerContext(httpRequest, httpResponse, crowbarViewContext);
                var viewEngineResult = crowbarViewContext.FindViewEngineResult(controllerContext);

                var view = viewEngineResult.View;
                if (view == null)
                {
                    var locations = new StringBuilder();
                    foreach (string searchedLocation in viewEngineResult.SearchedLocations)
                    {
                        locations.AppendLine();
                        locations.Append(searchedLocation);
                    }

                    throw new ArgumentException("The view was not found. The following locations were searched: " + locations, viewName);
                }

                try
                {
                    var viewData = new ViewDataDictionary(viewModel);
                    var tempData = new TempDataDictionary();

                    var viewContext = new ViewContextStub(controllerContext, view, viewData, tempData, writer)
                    {
                        ClientValidationEnabled = crowbarViewContext.ClientValidationEnabled,
                        UnobtrusiveJavaScriptEnabled = crowbarViewContext.UnobtrusiveJavaScriptEnabled
                    };

                    view.Render(viewContext, httpResponse.Output);
                    cookies = controllerContext.HttpContext.Response.Cookies;

                    httpResponse.Flush();
                }
                finally
                {
                    viewEngineResult.ViewEngine.ReleaseView(controllerContext, view);
                }

                return writer.ToString();
            }
        }
开发者ID:mrydengren,项目名称:crowbar,代码行数:56,代码来源:CrowbarController.cs

示例12: GenerateOutput

        public Stream GenerateOutput(dynamic shape)
        {
            var controller = new DummyController(_hca.Current().Request.RequestContext);

            using (var stream = new MemoryStream())
            using (var streamWriter = new StreamWriter(stream))
            {
                var originalContext = controller.ControllerContext.HttpContext;

                try
                {
                    // Get the Request and User objects from the current, unchanged context
                    var currentRequest = HttpContext.Current.ApplicationInstance.Context.Request;
                    var currentUser = HttpContext.Current.ApplicationInstance.Context.User;

                    // Create our new HttpResponse object containing our HtmlTextWriter
                    var newResponse = new HttpResponse(streamWriter);

                    // Create a new HttpContext object using our new Response object and the existing Request and User objects
                    var newContext = new HttpContextWrapper(
                                new HttpContext(currentRequest, newResponse)
                                {
                                    User = currentUser
                                });

                    // Swap in our new HttpContext object - output from this controller is now going to our HtmlTextWriter object
                    controller.ControllerContext.HttpContext = newContext;

                    new ShapePartialResult(controller, shape).ExecuteResult(controller.ControllerContext);

                    newResponse.Flush();
                    streamWriter.Flush();
                    stream.Flush();

                    // New stream so everything else here can be disposed
                    var responseStream = new MemoryStream();
                    stream.Position = 0;
                    stream.CopyTo(responseStream);
                    responseStream.Position = 0;
                    return responseStream;
                }
                finally
                {
                    // Setting context back to original so nothing gets messed up
                    controller.ControllerContext.HttpContext = originalContext;
                }
            }
        }
开发者ID:hqmirror,项目名称:Piedone.HelpfulLibraries,代码行数:48,代码来源:ShapeOutputGenerator.cs

示例13: CaptureViewOutput

        public static string CaptureViewOutput(Controller controller, ViewResult view)
        {
            var builder = new StringBuilder();
            using (var stringWriter = new StringWriter(builder))
            {
                using (var htmlTextWriter = new HtmlTextWriter(stringWriter))
                {
                    var currentContext = controller.ControllerContext.HttpContext;

                    try
                    {
                        // get the Request and User objects from the current, unchanged context
                        var currentRequest = HttpContext.Current.ApplicationInstance.Context.Request;
                        var currentUser = HttpContext.Current.ApplicationInstance.Context.User;

                        // create our new HttpResponse object containing our HtmlTextWriter
                        var newResponse = new HttpResponse(htmlTextWriter);

                        // create a new HttpContext object using our new Response object and the existing Request and User objects
                        var newContext = new HttpContextWrapper(
                                    new HttpContext(currentRequest, newResponse)
                                    {
                                        User = currentUser
                                    });

                        // swap in our new HttpContext object - output from this controller is now going to our HtmlTextWriter object
                        controller.ControllerContext.HttpContext = newContext;

                        // Run the ViewResult
                        view.ExecuteResult(controller.ControllerContext);

                        // flush the output
                        newResponse.Flush();
                        htmlTextWriter.Flush();
                        stringWriter.Flush();

                    }
                    finally
                    {
                        // and no matter what happens, set the context back!
                        controller.ControllerContext.HttpContext = currentContext;
                    }
                }
            }

            // our StringBuilder object now contains the output of the ViewResult object
            return builder.ToString();
        }
开发者ID:GroM,项目名称:Shaver,代码行数:48,代码来源:ControllerHelper.cs

示例14: SafeResponseEnd

        /// <summary>
        /// 安全的Response.End()
        /// </summary>
        public static void SafeResponseEnd(HttpResponse response, String title)
        {
            try
            {
                response.Flush();

                response.End();

                Thread.Sleep(2000);
            }
            catch (ThreadAbortException tae)
            {
                //Logger.LogInfo("PublicMethodBLL", "SafeResponseEnd", 0,
                //    "\"" + title + "\"页面在Response.End()时发生异常,只做为记录,不影响程序正常运行。",
                //    tae.StackTrace + tae.Source);
            }
        }
开发者ID:loozhang,项目名称:WebApplication3---copy,代码行数:20,代码来源:PublicMethod.cs

示例15: ExportGridViewToExcel

        public void ExportGridViewToExcel(GridView grid, string fileName, HttpResponse Hresponse)
        {
            Hresponse.Clear();
            Hresponse.Buffer = true;
            Hresponse.AddHeader("content-disposition", "attachment;fileName=" + fileName + ".xls");
            Hresponse.Charset = "";
            Hresponse.ContentType = "application/vnd.ms-excel";

            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            grid.RenderControl(hw);
            Hresponse.Output.Write(sw.ToString());
            Hresponse.Flush();
            Hresponse.Close();
            //Hresponse.End();
            Hresponse.OutputStream.Close();
        }
开发者ID:JonathanFernandez,项目名称:Pirelli,代码行数:17,代码来源:PirelliMetodos.cs


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