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

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

问题描述

我是动态生成HTML文件。这是格式化的CSS和图像。我要找的代码应该能够执行按钮点击其中,并询问位置保存文件。还应该下载的HTML文件中引用了关注资源文件。我有什么代码呢?我可以使用Web客户端的一样吗?

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 ?

推荐答案

有在ASP.NET没有另存为对话框。因为它是在浏览器中运行。必须将用户的文件系统,包括另存为对话框的访问权限。

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)

您可以创建这样一种情况,如果你让你的文件中可用,您可以使用Web客户端通过URI,看到的这个帖子。

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

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

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