c#代码下载生成html文件在asp.net [英] c# code for download generated html file in asp.net

查看:115
本文介绍了c#代码下载生成html文件在asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态生成html文件。它是用Css和Images形成的。我正在寻找应该能够在按钮点击执行的代码,并要求保存文件的位置。还应该下载html文件中引用的关注资源文件。我要做什么代码?我可以使用WebClient相同吗?

解决方案

在ASP.NET中没有另存为对话框。因为它在浏览器中运行。您不能访问用户的文件系统,包括另存为对话框。



但是您可以将用户的文件作为附件发送,大多数浏览器将显示一个对话框询问用户是否保存文件或打开文件。也许用户会选择保存它。

  Response.ContentType =application / octet-stream(或内容类型为文件)。 
Response.AppendHeader(content-disposition,attachment; filename =& strFileName)

您可以创建一种情况,您可以通过uri将文件提供给WebClient,请参阅这个的帖子。


I am dynamically generating html file. It is formated with Css and Images. I am looking for code which should able to execute on button click, and ask the location for saving file. also it should download concern resource files which has referenced in html file. What code i have to do ? Can i use WebClient for the same ?

解决方案

There is no "Save As" dialog in ASP.NET. Since it is running in a browser. You have no access to the user's file system, including the Save As dialog.

But you can send the user a file, as an attachment, most browsers will display a dialog asking the user whether to save the file or open it. Maybe the user will choose to save it.

Response.ContentType = "application/octet-stream" (or content type of your file).
Response.AppendHeader("content-disposition", "attachment;filename=" & strFileName)

You could create a situation where you can use WebClient if you make your file available through a uri, see this post.

这篇关于c#代码下载生成html文件在asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆