Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving Data to a Local Text File 1

Status
Not open for further replies.

stein555

Programmer
Apr 18, 2003
24
US
I am very new to programming. I started about 1 month ago. I am currently stuck on an issue with saving data from an SQL table into a local text file (exporting of some sort).

I have no problem connecting to the SQL database (reading, writing, etc.) but when I attempt to write anything to a text file, it doesn't work.

With this code, I get a path not found error.

set textDB = Server.CreateObject("Scripting.FileSystemObject")
set rsText = textDB.OpenTextFile("C:\Inventory\Inventory.txt",8,TRUE)
rsText.WriteLine("This is a test...")
rsText.Close


The page resides on a web server at work and I am attempting to save the file on my local c: drive. There is a directory called Inventory on my C: drive (and I have tried putting an empty Inventory.txt file in it as well).

Is it trying to save the file to the server? What am I doing wrong?

Thank you in advance for your help!
 
This saves it on the webserver. You can't have it save on your PC, unless you go through the Inet. I wouldn't recommend it, it's very unsecure.

-Bad Dos
 
Hmmm. Ok...

Security is not an issue because this is an enclosed LAN at work (i.e. the only people allowed to access the web page work for the company behind the firewall).

I guess I will have to try a different route to get the data exported.

Thanks for your help.
 
Ok I have another question then...

Is there anyway to provide a User Name and Password in the ASP code itself for creating a text file on the server with that code?

I am thinking that I can just have the user download the file to their pc after it is created, but I have to grant the web page access to the server in order to write the data.

Thanks again.
 
You can have to FSO write to a network share, but you need to make a local account on the File server to match that of the account that anonymous access is running under on the IIS settings.

<%
Set textDB = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set rsText = textDB.OpenTextFile(&quot;\\someserver\theshare\Inventory\Inventory.txt&quot;,8,TRUE)
rsText.WriteLine(&quot;This is a test...&quot;)
rsText.Close
%>
 
Cool! Thanks =) I will probably start working on that now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top