【问题标题】:How to use HttpContext in a Windows application?如何在 Windows 应用程序中使用 HttpContext?
【发布时间】:2014-10-13 11:31:12
【问题描述】:

我想将数据表单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();

【问题讨论】:

  • 你不能在 winforms 或 WPF 应用程序中远程做任何事情。
  • 还有其他方法吗? @本罗宾逊
  • 你到底想做什么?您发布的代码与基于非 http 的应用程序无关。

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


【解决方案1】:

你不能。 ASP.NET 无法与 WPF 或 Windows 窗体相媲美。

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

我建议只给File.WriteAllText

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-26
    • 2023-03-28
    • 2011-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2013-10-25
    相关资源
    最近更新 更多