如何为下载文件创建控件 [英] How to create a control for download files

查看:79
本文介绍了如何为下载文件创建控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


谁能告诉我如何创建控件来下载word,xml,text,jpg文件.
实际上,在我的应用程序中有一个链接,我想要打开该文件的onclick链接,但是如果是word,则不要显示该opensavefiledialog,它将显示在某些asp.net控件中.
我尝试使用iframe,但失败了...任何人都知道其他控件.

请帮助我...

Hi,
Can any one tell me how to create control to download word,xml, text ,jpg files.
Actualy there is one link in my application and onclick of that i want to open that file, but if it is word then do not display that opensavefiledialog and it will appear in some asp.net control.
I tried by using iframe but it fails...any one know any other control..

plz help me...

推荐答案

问题不在于编写控件,而是在于在发送文件时设置文件的mime类型,将确定文件是否已下载或由Word打开.当然,Word需要在客户端计算机上.
The issue is not in writing a control, it''s in setting the mime type of the file when you send it, that will determine if the file is downloaded, or opened by Word. Of course, Word needs to be on the client machine.


更进一步的基督徒回答.

MIME类型告诉浏览器正在传输什么类型的文件,以便可以使用正确的应用程序查看文件.

要停止打开/保存文件对话框,您需要将响应上的"content-disposition"标头设置为内联",这将跳过打开/保存对话框,除非没有用于该MIME类型的查看器,在这种情况下,打开/保存保存对话框仍将打开.
您将不得不控制下载过程,而不仅仅是链接到文件.
Further to Christians answer.

The MIME type tells the browser what type of file is being transmitted so the correct application can be used to view the file.

To stop the open/save file dialog you will need to set the "content-disposition" header on the response to "inline" this will skip the open/save dialog unless there is no viewer for that MIME type in which case the open/save dialog will still open.
You are going to have to take control of the download process and not just link to the file.



我使用以下代码解决了我的问题:

I solved my issue using following code:


这篇关于如何为下载文件创建控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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