user1292656
user1292656

Reputation: 2560

Javascript: Save file with ActiveXobject

I am working on an Asp .net project and i have a textarea in an aspx page, and i am trying to save textarea contents on a file on the server by clicking a button with the following code:

           var fso = new ActiveXObject("Scripting.FileSystemObject");
           var a = fso.CreateTextFile("c:\\temp1\\testfile.txt", true);
               a.WriteLine(saveData);
           a.Close();

The issue is if the file does not exists , then it creates it. But if it exists it dodes not overwrite it. Any help pls ? (I have to mention that Localy runing the application with visual studio then it rewrites it, but it doesnt works on the published version )

Upvotes: 0

Views: 2013

Answers (1)

Teemu
Teemu

Reputation: 23396

Use rather OpenTextFile() than CreateTextFile(). It also creates non-existing file if needed.

var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile("c:\\temp1\\testfile.txt",2, true);
a.WriteLine(saveData);
a.Close();

Upvotes: 3

Related Questions