473,396 Members | 2,020 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,396 software developers and data experts.

Process a CSV File in ASP.

MN
Hello all -

I'm hoping that someone knows the answer to this as I have not done this in
ASP before.

Basically, I need to select a csv file from my desktop through the
"Browse.." button in my ASP page and upload the file and do further
interrogation and extract the data to put into a database. What I'm
struggling with is more the first parts with getting the file read properly
in the second page so I can read and insert the data. The data below
describes the file. Quite a simple format.

Customer ID - Additional values are player IDs
193948294, 293, 294, 296, 290, 292

If anyone can help, I would greatly appreciate it. Thanks for reading.
Mark

May 23 '06 #1
3 8361
I use an script from Persists ASP Upload to get the file properly to
the right location but here is what i do for that reason. It is a free
download

Upload Form
<html>
<head><title>Upload Log Hours Form</title></head>
<body style="font-family: Arial">
<h3 class=View>Upload CSV File</h3>
<TABLE BORDER=0 WIDTH=70% CELLSPACING=0 COLSPAN=10>
<FORM ACTION="uploadfile.asp" METHOD="POST"
ENCTYPE="multipart/form-data">
<tr>
<td class=view><b>File Name</td><td class=view><input type=file
name="fname" size="36"></td>
<tr>
<tr><td class=view><input type=submit name=submit value=Upload></td><td
class=view><input type=reset name=submit value=Reset></td>
</form>
</table>
</body>
</html>
Second Page

<HTML>
<head><title>IMPORT</title></head>
<BODY>
<%

Set Upload = Server.CreateObject("Persits.Upload.1") 'Persists ASP
Upload Object
Upload.OverwriteFiles = False
Count = Upload.Save(Server.MapPath("\upload\")) 'Path to upload To
Dim faname
Dim i

faname(i) = File.Path
i = i +1
Next
Dim aVars(8) 'Amount of columns you project per line, if this is
dynamice per line use a REDIM Preserve on your FOR statement to REDIM
your array
Dim oStream
Dim sData
Dim aData
Dim oFSO
Set oFSO = CreateObject( "Scripting.FileSystemobject" )
Set oStream = oFSO.OpenTextFile( faname )
Do While oStream.AtEndOfStream = False 'Will Walk Through all the
records
sData = oStream.ReadLine
aData = Split( sData, "," )
newrec = newrec + 1
For i = 0 To ( UBound( aData ) )
aVars(i) = aData(i)
aVars(i) = TRIM(aVars(i)) ' Removes and blank spaces before and
after the Data
Next
'..
'.. Write To your database
'.. aVars(0) will be your first
Loop
%>
</BODY>
</HTML>

Ok here's how the second page works,
The file is downloaded to a specific location that you specify
Then your file is opened and read line by line until it is finished.
Every Line it reads it splits the data into an array for you to use
later as aVars(0), aVars(1) and so on.
Then the each Variable in the array is read and TRIM'd to remove any
spaces that may cause DB problems.
After that you can write it to your database using which ever type you
would like.
Let me know if this works out for you

May 23 '06 #2
Sorry that was really bad code

<html>
<head><title>Upload CSV</title></head>
<body style="font-family: Arial">
<h3 class=View>Upload CSV File</h3>
<TABLE BORDER=0 WIDTH=70% CELLSPACING=0 COLSPAN=10>
<FORM ACTION="uploadfile.asp" METHOD="POST"
ENCTYPE="multipart/form-data">
<tr>
<td class=view><b>File Name</td><td class=view><input type=file
name="fname" size="36"></td>
<tr>
<tr><td class=view><input type=submit name=submit value=Upload></td><td

class=view><input type=reset name=submit value=Reset></td>
</form>
</table>
</body>
</html>
Second Page
<HTML>
<head><title>IMPORT</title></head>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload.1") 'Persists ASP
Upload Object
Upload.OverwriteFiles = False
Count = Upload.Save(Server.MapPath("\upload\")) 'Path to upload To
Dim faname
faname = File.Path
Dim aVars(8) 'Amount of columns you project per line, if this is
dynamice per line use a REDIM Preserve on your FOR statement to REDIM
your array
Dim oStream
Dim sData
Dim aData
Dim oFSO
Set oFSO = CreateObject( "Scripting.FileSystemobject" )
Set oStream = oFSO.OpenTextFile( faname )
Do While oStream.AtEndOfStream = False 'Will Walk Through all the
records
sData = oStream.ReadLine
aData = Split( sData, "," )
newrec = newrec + 1
For i = 0 To ( UBound( aData ) )
aVars(i) = aData(i)
aVars(i) = TRIM(aVars(i)) ' Removes and blank
spaces before and
after the Data
Next
'..
'.. Write To your database
'.. aVars(0) will be your first
Loop
%>
</BODY>
</HTML>

May 23 '06 #3
MN
Nico -

Millions of thanks. Worked perfect.

Mark

"Nico VanHaaster" wrote:
Sorry that was really bad code

<html>
<head><title>Upload CSV</title></head>
<body style="font-family: Arial">
<h3 class=View>Upload CSV File</h3>
<TABLE BORDER=0 WIDTH=70% CELLSPACING=0 COLSPAN=10>
<FORM ACTION="uploadfile.asp" METHOD="POST"
ENCTYPE="multipart/form-data">
<tr>
<td class=view><b>File Name</td><td class=view><input type=file
name="fname" size="36"></td>
<tr>
<tr><td class=view><input type=submit name=submit value=Upload></td><td

class=view><input type=reset name=submit value=Reset></td>
</form>
</table>
</body>
</html>
Second Page
<HTML>
<head><title>IMPORT</title></head>
<BODY>
<%
Set Upload = Server.CreateObject("Persits.Upload.1") 'Persists ASP
Upload Object
Upload.OverwriteFiles = False
Count = Upload.Save(Server.MapPath("\upload\")) 'Path to upload To
Dim faname
faname = File.Path
Dim aVars(8) 'Amount of columns you project per line, if this is
dynamice per line use a REDIM Preserve on your FOR statement to REDIM
your array
Dim oStream
Dim sData
Dim aData
Dim oFSO
Set oFSO = CreateObject( "Scripting.FileSystemobject" )
Set oStream = oFSO.OpenTextFile( faname )
Do While oStream.AtEndOfStream = False 'Will Walk Through all the
records
sData = oStream.ReadLine
aData = Split( sData, "," )
newrec = newrec + 1
For i = 0 To ( UBound( aData ) )
aVars(i) = aData(i)
aVars(i) = TRIM(aVars(i)) ' Removes and blank
spaces before and
after the Data
Next
'..
'.. Write To your database
'.. aVars(0) will be your first
Loop
%>
</BODY>
</HTML>

May 29 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Justin Johnson | last post by:
Hello, I was wondering if anyone has seen this behavior before for the process.py module available at http://starship.python.net/crew/tmick/. I've been using it quite well on windows 2000...
1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
11
by: Mike M | last post by:
Is it possible? In the parent process, I have a socket that binds, listens and then accepts new connections (which creates new sockets in the process). I want to be able to pass some of these new...
0
by: Markus Poehler | last post by:
Hi my program should run on terminal server. I open Acrobat process and I have to kill them at some points in my application. This fails cause of insufficient rights on terminal server. the...
10
by: Sorin Dolha [MCSD .NET] | last post by:
I would like to start a process from C# code as another user. The C# code is executed as the ASPNET user because it relies in a Web Page class, and I would like that the process will run as another...
3
by: BCM | last post by:
In a simple console app the following few lines open up an Acrobat file without a hitch: Process p = new Process(); p.StartInfo.FileName = @"C:\test.pdf"; p.Start(); But the same code in an...
12
by: Raymond Lewallen | last post by:
How to wait for a process to stop completion is my goal. Obviously, the looping while waiting for the HasExited property is not a solution.. but thats the best I can come up off the top of my...
0
by: WATYF | last post by:
This is my problem... I have some code that starts a Process and returns it to a variable... (prcBat) At any time while that process is running... I want to be able to Kill it by pressing a...
4
by: Paddy | last post by:
We have a recurring problem where a (long-running) service throws an exception while trying to access a file. The problem is that this is very rare (happens once every week and without warning) but...
7
by: jonathandrott | last post by:
sorry newbie question probably. i'm trying to open an specific folder. open each file with in the folder individually and process each one. all the processing code has been written. i'm looking...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.