Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2005, 05:23 AM
Authorized User
 
Join Date: Jun 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default write values to txt file in server

Hello,

I don't work with javascript but to finish a project to a client my company needs to do several things. One of them it's to give to the client a few scripts that make some calculations and at the end the values will need to be written to a txt file in the server (this will work in a Intranet). A read about Javascript and I understood (correct me if I'm wrong...) it works from the client-side, so it's not possible to write to the server. I also read some question in a search I made in Google and in some sites they talked about using the FileSystemObject. Does any of you knows another way of dealing with this or have other suggestions? I'll appreciate all the help you can get.

thanks,


Elisa Resina

Elisa Resina
__________________
Elisa Resina
 
Old July 13th, 2005, 02:41 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Server side code runs on the server, if you are using ASP then server side code can be written in VBScript or JScript (Microsoft's version of JavaScript/ECMAScript). If you are using a different server side framework, e.g. Apache then you can use PHP and other languages server side.
In JScript you can write text files to the server, providing the account has permissions, using the FileSystemObject. There are dozens of examples in Google and also at Microsoft's FileSystemObject Reference

--

Joe (Microsoft MVP - XML)
 
Old July 13th, 2005, 03:36 AM
Authorized User
 
Join Date: Jun 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Joe and thanks for your answer. The client is using Apache and send to me a few javascripts that I should change to make what I explained before. I don't have a way to reproduce here in the office the real situation (I never went to the client company, we only spoke by e-mail...this is not what I wish but it's what I have to do...). To reproduce a small part of the code I put very small html file in our server with that code using the FileSystemObject and it didn't work (the message was "Error: Number:-2146827859 Description:Automation server can't create object"). Why, I don't have any idea...Something missing...Microsoft scrip host? I don't know...

If after this long and boring message you still have any suggestion, they will be very apreciate...

Thank you again

Elisa



Elisa Resina
 
Old July 13th, 2005, 03:46 AM
Authorized User
 
Join Date: Jun 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well, just a note...the code works IN the server...not if I run it through the browser...

regards,

Elisa

Elisa Resina
 
Old July 13th, 2005, 10:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That error doesn't make sense, are you sure you're running the code server side? I don't see how you can be if they are running Apache. Can you show a small sample of your web page?

--

Joe (Microsoft MVP - XML)
 
Old July 15th, 2005, 05:02 AM
Authorized User
 
Join Date: Jun 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, Joe. Sorry for the delay.

Here goes:

Code:
<html>
<head> 
<script language="JavaScript" runat="server">
 function WriteToFile() {
 try {
  var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("d\Inetpub\wwwroot\testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();

 }
catch(err){
  var strErr = 'Error:';
  strErr += '\nNumber:' + err.number;
  strErr += '\nDescription:' + err.description;
  document.write(strErr);
 }
}
</script>

</head> 
<body onload='WriteToFile();'> 

</body> 
</html>
This is my last version. I tested it in a IIS server and of course in apache it won't work in this way.

I found this in google:

https://lists.latech.edu/pipermail/j...ne/003755.html

It looks like the same error I have. Does it make sense to you?

regards,

Elisa


Elisa Resina
 
Old July 17th, 2005, 05:36 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That code will work if the server rune IIS and allows use of the FileSystemObject, the trouble is your path is incorrect, change:
Code:
"d\Inetpub\wwwroot\testfile.txt"
to
Code:
"d:\\Inetpub\\wwwroot\\testfile.txt"
--

Joe (Microsoft MVP - XML)
 
Old July 19th, 2005, 08:23 AM
Authorized User
 
Join Date: Jun 2003
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, Joe.

The code now runs perfectly in IIS server and in an Apache Server

Thank you very much for all your help and time.

Regards,

Elisa Resina





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP write to txt file dizzy1 Classic ASP Basics 7 June 15th, 2010 10:38 PM
write the values of textbox to a file sandhyamn Pro JSP 1 May 23rd, 2007 10:04 AM
Problem : Write to txt file al-hijjawi ASP.NET 1.0 and 1.1 Basics 0 April 10th, 2006 04:32 AM
write values to txt file in server eresina Javascript How-To 1 July 19th, 2005 05:11 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.