c#代码下载生成html文件在asp.net [英] c# code for download generated html file in asp.net
问题描述
在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屋!