html - how to save file in relative path using javascript - Stack Overflow

I want to save .json file in application path using javascript.I used the following code to save the f

I want to save .json file in application path using javascript. I used the following code to save the file. but it saved in physical path. not in the application path. my code is:

 var fso = new ActiveXObject("Scripting.FileSystemObject");
 var s = fso.CreateTextFile("E:\\Model.json", true);
 s.WriteLine(json);
 s.Close();

in server side can use Server.MapPath but i dont know how to save in Javascript. please guide me friends, thanks in advance..

I want to save .json file in application path using javascript. I used the following code to save the file. but it saved in physical path. not in the application path. my code is:

 var fso = new ActiveXObject("Scripting.FileSystemObject");
 var s = fso.CreateTextFile("E:\\Model.json", true);
 s.WriteLine(json);
 s.Close();

in server side can use Server.MapPath but i dont know how to save in Javascript. please guide me friends, thanks in advance..

Share Improve this question asked Apr 6, 2012 at 11:28 ganeshganesh 8996 gold badges15 silver badges29 bronze badges 1
  • Do you intend to run this script inside a webpage? I doubt if it would work that way. – Salman Arshad Commented Apr 6, 2012 at 11:30
Add a ment  | 

2 Answers 2

Reset to default 1

I take it you're running this via Windows Scripting Host or similar.

Just use a relative path:

var s = fso.CreateTextFile("Model.json", true);

Note I left the E:\\ off.

I don't know what you mean by "the application path," but that will save the file in the current directory in which the script/application is running. If you want to do it relative to one of the "special" Windows folders, use FileSystemObject#GetSpecialFolder to get the special folder's path, then append your path to it.

Can't you just strip the drive prefix amd use relative path?

 var fso = new ActiveXObject("Scripting.FileSystemObject");

 var s = fso.CreateTextFile("MyFolder\\Model.json", true);

 s.WriteLine(json);
 s.Close();

And also, from looking at the FSO documentation there are several ways to obtain the current directory path and pute the path yourself as well.

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

相关推荐

  • html - how to save file in relative path using javascript - Stack Overflow

    I want to save .json file in application path using javascript.I used the following code to save the f

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信