473,226 Members | 1,544 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,226 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 8344
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: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.