通过javascript打开并保存文件 [英] Open and save a file through javascript

查看:96
本文介绍了通过javascript打开并保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要打开类型(pdf,doc,docx,xl​​sx等)的文档,然后下载并保存.

整个场景是:

我正在一个移动网站上工作,用户可以登录并添加其中的一些信息,然后根据上述类型给出的这些信息创建一些文档.
现在这些文件的标题列在"ul,li"中
这些文档也不会保存在任何文件夹中,否则其内容将以字节数组及其扩展名的形式保存在数据库中.当我单击链接时,它应该获取所有信息,并出现一个弹出窗口,询问是否保存或打开文件.如果单击保存",它将下载文件并将其保存在手机的SD卡中.

现在,请让我知道我该怎么做:

Hye,

I need to open a document of type (pdf, doc, docx, xlsx etc) and download and save it.

The whole scenario is:

I am working on a mobile website where user can log in and add some of there information and then some documents are created according to these information given of the above types.
Now the Title of those documents are listed in "ul, li"
Also these Documents are not saved in any folder but else its contents are to be saved in Database as byte array along with its extension. At the time I click the link, it should fetch all the information and a popup should appear asking whether to save or open the file. If I click save, it should download the file and save it in mobile''s SD card.

Now, Please let me know how can I do this :

this.Response.Clear();
               this.Response.ContentType = MimeType;
               this.Response.AppendHeader("Content-Disposition", "attachment;filename=demoFile" + DocumentExtension);
               Response.OutputStream.Write(DocumentContent, 0, DocumentLength);
               Response.Flush();
               Response.Close();




通过javascript.

有什么办法.
如果没有,我该如何打开或保存文件,如果单击保存",则会下载并保存.

我没有该文件的任何路径,因为该文件未保存在某处,所有数据均取自数据库.

我必须渲染字节数组,我该怎么办.

提前谢谢.

[也请选择在javascript中使用代码]




through javascript.

Is there any way.
and if not, how can I let a file either to open or save and if clicked "save" it downloads and save.

I don''t have any path for that file, as the file is not saved somewhere, all the data is taken from database.

i have to render the byte array, how can I do this.

Thanks in advance.

[Also please prefer the code is to be in javascript]

推荐答案

您可以通过javascript打开word/excel.您必须使用ActiveX对象.这是链接. Open_Word_Excel_using_JavaScript [
You can open word/excel through javascript. You have to use ActiveX object. here is link. Open_Word_Excel_using_JavaScript[^]


Hye,

我已经使用网络服务完成了.
当时我单击链接下载文件,
调用了一个Web方法,该方法从
检索该文档的字节数组. 数据库,准备文档并将其写在响应上.
浏览器本身开始下载该文件,因为它不支持打开格式.

干杯..:)
Hye,

I have done it using web service.
At the time I click a link to download a file,
a web method is called, which retrieve the byte array of that document from
Database, prepare the document and write it on the response.
The browser itself starts downloading that file, as it doesn''t support the format to open.

Cheers.. :)


这篇关于通过javascript打开并保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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