c# - How to create and save a text file with JavaScript - Stack Overflow

Do you know any cross-browser method to create and save a file with JavaScript on the client-side?Consi

Do you know any cross-browser method to create and save a file with JavaScript on the client-side?

Considerations:

  1. I can't save it on the server because the file is going to be read from a fiscal printer.
  2. The server can't access the client. This is obvious because we are talking about a web application in the web, so the server can't access a client folder.
  3. New ActiveXObject("Scripting.FileSystemObject"); is ONLY for Internet Explorer and even then not for all versions.
  4. We are talking about printing on a fiscal printer, so I can't ask the cashier in the supermarket to download the text file and save it in a folder where the fiscal printer can read it.
  5. If not JavaScript, what else can I use in my ASP, .Net 4.0, C# web application?

Do you know any cross-browser method to create and save a file with JavaScript on the client-side?

Considerations:

  1. I can't save it on the server because the file is going to be read from a fiscal printer.
  2. The server can't access the client. This is obvious because we are talking about a web application in the web, so the server can't access a client folder.
  3. New ActiveXObject("Scripting.FileSystemObject"); is ONLY for Internet Explorer and even then not for all versions.
  4. We are talking about printing on a fiscal printer, so I can't ask the cashier in the supermarket to download the text file and save it in a folder where the fiscal printer can read it.
  5. If not JavaScript, what else can I use in my ASP, .Net 4.0, C# web application?
Share Improve this question edited Mar 5, 2020 at 19:50 the Tin Man 161k44 gold badges221 silver badges306 bronze badges asked Sep 12, 2011 at 18:20 eKelvineKelvin 9251 gold badge9 silver badges25 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4

Basically, you said it, "we are talking about a web application." Do you know any web applications that save a file to your hard drive (besides cookies) without showing you a download prompt first?

Having said that, browsers have started to offer a persistence API that goes beyond cookies. (See, for example, this article.) But such a solution wouldn't meet your requirement of being cross-browser.

Your only options are to use persistance APIs from HTML5 or to create a browser plugin (activex control on IE, NPAPI plugin on others) that can do the file access for you. You could use FireBreath to do this, and it would be relatively simple if you know C++.

That said, it is a really dangerous idea; it is difficult to prevent people from using your plugin in other pages, so your plugin has to somehow be smart enough to keep itself from being abused by malicious sites that want to read (or even write) arbitrary data to your hard drive.

There is, after all, a reason why browsers don't natively support this. I'd look at HTML5.

you can do that by Client side Web services just make a function in web service to create a text file in your hard drive then convert the web service in to the client side service when u do that .Net framework make a client side java script then u will be able to call the server side function using Java script in client side after that your file will not be posted in the server it will remain save in your hard drive ok

we came out with a simple windows service nodejs app to be installed in the local machine. When the web application need to create a file it just sends an API call to this app using localhost and that will write the file for it. Cheers.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745194116a4616007.html

相关推荐

  • c# - How to create and save a text file with JavaScript - Stack Overflow

    Do you know any cross-browser method to create and save a file with JavaScript on the client-side?Consi

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信