如何在Windows应用程序中使用HttpContext?

时间:2014-10-13 11:31:12

标签: c# asp.net .net windows httpcontext

我想将数据格式html绑定到excel。在asp.net中我们使用它。

如何在Windows应用程序中执行此操作?

Response.AddHeader("Content-Disposition", "attachment;filename=" + filename + ".xls");
Response.ContentType = "application/vnd.xls";
Response.Cache.SetCacheability(HttpCacheability.NoCache); // not necessarily required
Response.Charset = "";
Response.Output.Write(htmlCodeFile);
Response.End();

1 个答案:

答案 0 :(得分:1)

你做不到。 ASP.NET无法与WPF或Windows Forms相媲美。

HttpContext特定于ASP.NET。没有办法在客户端代码上重用它。您的代码准备并从服务器向客户端发送HTTP响应。该方案不适用于客户端应用程序。

我建议只使用File.WriteAllText

File.WriteAllText(@"C:\somefile.xls", htmlCodeFile);