473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Creating text files from a db

Greetings.

I'm not very proficient in asp- just started last month. Sorry if this has already been answered- didn't know what to search for.

I'm trying to create multiple text files from a database. I have already created an asp file which returns all of the rows from the db. However, I want the asp to generate one file for each row in the db.

Here is what I want to do...

<%

Const fsoForWriting = 2

Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Open the text file
Dim objTextStream
Set objTextStream = objFSO.OpenTextFile("C:\Inetpub\wwwroot\dynamic file name", fsoForWriting, True)

'Display the contents of the text file
objTextStream.WriteLine "Hello World"

Here is where the qestion is... how do I get this to write asp here instead of static text?

'Close the file and clean up
objTextStream.Close
Set objTextStream = Nothing
Set objFSO = Nothing

%>

Does this make any kind of sence, or am I just confused and/or confusing?

Thanks in advance for any help!!

Best regards,

Rich Wertz
Aug 3 '07 #1
3 1263
Just nevermind the previous post- I got it to work, but there is a problem... The info that is being written to each file is off by 1 line in the database.

The asp created a file named c01s01a01i01.txt, (the name comes from info in the database) but the contents of this file is supposed to be from the same line where the name comes from, but it ends up being content from the line right after. So c01s01a01i02.txt actually has the info from the db corresponding to c01s01a01i03.

I remember hearing at some point in life that this happens, but I don't know how to fix it. Is it a simple problem? Also, has anyone else experienced this?

Thanks for any help and please tell me if I'm not being clear enough. It is so hard to explain!!!

Best,
Rich
Aug 3 '07 #2
shweta123
692 Expert 512MB
Hi,

Do you want to take filename from Database? Are you stuck there?
You can do it this way
<%
Dim Rs
Dim con
Dim Sql
Sql =".........."

set Rs =con.execute(Sql)
If not Rs.eof then
Dim filename
filepath ="c:\...."
filename=filepath & "\" Rs(0)

Dim objTextStream
Set objTextStream = objFSO.OpenTextFile(filename, fsoForWriting, True)
end if
%>

Hope so this is what you want.




Just nevermind the previous post- I got it to work, but there is a problem... The info that is being written to each file is off by 1 line in the database.

The asp created a file named c01s01a01i01.txt, (the name comes from info in the database) but the contents of this file is supposed to be from the same line where the name comes from, but it ends up being content from the line right after. So c01s01a01i02.txt actually has the info from the db corresponding to c01s01a01i03.

I remember hearing at some point in life that this happens, but I don't know how to fix it. Is it a simple problem? Also, has anyone else experienced this?

Thanks for any help and please tell me if I'm not being clear enough. It is so hard to explain!!!

Best,
Rich
Aug 3 '07 #3
Hi shweta123...

Thanks so much for that... I'm not sure how I could have overlooked that!!
It's funny that I write the same thing as "Set RS = DB.Execute (SQL)" and you wrote it different in your reply, but in the end, I forgot the "DB." part and just expected the whole thing to execute, I guess!! ;)

Thank you so much for your help and in case you are wondering, I have now generated all 2,411 files I needed- all from a single asp file of about 186 lines.

I got this assignment yesterday morning and told everyone in the meeting that it would take about a week to produce these files- not sure I'm going to let on that they're done... then I can sit back and watch You Tube for the next 13 days!!!

All hail and sing the praises of ASP!!!

Thanks again!!

-Rich
Aug 3 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Todd_M | last post by:
I was wondering what anyone might suggest as "best practice" patterns for streaming out fixed formatted text files with C#? Let's say we get our data in a dataset table and we need to iterate over...
9
by: Sheldon Cohen | last post by:
Hello, I am using c# and running a site that is on a shared host. The code in question is supposed to create a new directory that is coming out of a text box. It works fine on my computer, but...
9
by: Maziar Aflatoun | last post by:
Hi everyone, I like to export some data from the database and allow my users to store this file to their harddrive as a .txt file. Does anyone know how I would go about doing that? (without...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
7
by: andym | last post by:
Dear All, I wish to have an ASP page that displays a predetermined date in the middle of a string. I wish this date to be set in a seperate control panel type page. I am hoping somebody could...
2
by: Astra | last post by:
Hi All Creating an rss.xml file dynamically via ASP/ADO/DB, but find errors in the file. Don't think it's an ASP prob to be honest. Think its more to do with the fact that the ampersands are...
1
by: Jumping until blue | last post by:
I'm confused ... and need some advice Here is what I want to do: I have a number of files, mostly text files formatted using Markdown syntax but also pdfs and other types of files, that are...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
0
by: Bomac8 | last post by:
I have a text file with "|" as a delimeter with three (3) fields XXX-12345|\\YYYYYYY|\\ZZZZZZZZ I need to read these files into an output folder. The problem that I'm having is that I need to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.