locked
problem or reading and writing textdata with a file in javascript and aspx page RRS feed

  • Question

  • User-458598543 posted

    Hello, I want to read or and write textdata with a file using javascript language. For this, I used activeXObject 'Scripting.FileSystemObject'. I'm trying the process to read a text file but the variable is empty. Which person have a solution ? Thanks !

    PS. : I'm testing with internet explorer and firefox but there is no result !
    Thursday, August 15, 2019 9:37 AM

All replies

  • User475983607 posted

    ActiveX does not exist in modern browsers but modern browser can read files.

    https://developer.mozilla.org/en-US/docs/Web/API/FileReader

    Thursday, August 15, 2019 10:55 AM
  • User-458598543 posted
    I think it would be interessing to find a solution of javascript file reader that be abality with each navigator and in most of versions for an international and popular used. Somebody have ie10, others edge, others ie7 or others google-chrome ... Thanks !
    Thursday, August 15, 2019 11:54 AM
  • User753101303 posted

    Hi,

    For safety reason a browser is not supposed to be able to read/write a client side file without any user action (using ActiveX is outdated and anyway it required changing security settings by hand or automatically on enterprise managed computers).

    What is the exact scenario ? The usual approach is to have the user selecting a file using the input type="file" tag. You can then access the content of this file (most often but not limited to uploading this content) and you can then also trigger a file save (with once again the user telling explicitly which file to write).

    Or see https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/offline-for-pwa#current_and_future_offline_storage_work depending on your exact need ?

    Thursday, August 15, 2019 12:05 PM
  • User-458598543 posted
    I saw that it's difficult to find a function to read or write txt files in javascript. The 'input' html object is interessant. Perhaps, integrate à javascript module as ajax or PHP module would be possible to put a writing textfile ASP function !?
    Thursday, August 15, 2019 4:26 PM
  • User288213138 posted

    Hi Rednuts72,

    As PatriceSc said, browsers cannot read/write directly the file from client.

    HTML 5 new API can only allow you to read files.

    But if you want to write data, you can try to pass textdata to the server, then code the file using some server-side language, and finally write the textdata by downloading it.

    Best regards,

    Sam

    Friday, August 16, 2019 9:51 AM
  • User753101303 posted

    We would need to understand your exact scenario and the purpose of this file. It is really needed only on the client side (and do you even need this to be a file or could localStorage fir your need) ??? The common pattern is likely to upload, process and download files....

    Friday, August 16, 2019 9:58 AM
  • User-458598543 posted
    With a little retard answer, my scenario is to write datatext in a file and save the file in localstorage and read data. I know the solution in c# language and in this excepted case I want to used JavaScript language. Thanks !!
    Saturday, September 7, 2019 10:14 PM