OpenTextFile

Author Message
Chriz

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 7/29/2008
  • Status: offline
OpenTextFile Tuesday, July 29, 2008 7:16 AM (permalink)
0
Hi,
I'm new here and to VBScript. I need to open a CSV file and store these data in the database. I already fail on opening the CSV, because FileExists returns FALSE and I have no idea how to find out the exact file position.
Here's the script I wrote so far:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
 <%
 Option Explicit
 On Error Resume Next
 
 Const ForReading = 1, ForWriting = 2, ForAppending = 8
 
 Dim strCsvFile
 strCsvFile = Server.MapPath("test.csv")
 'response.write(strCsvFile)
 Set objFSO = CreateObject("Scripting.FileSystemObject")
 
 ' check existance
 if (not objFSO.FileExists(strCsvFile)) then
     response.write(strCsvFile & " does not exist")
     response.end
 end if
 
 ' open file
 Set objFile = objFSO.OpenTextFile(strCsvFile, ForReading, false)
 Dim strLine, arrLine, strSqlInsert
 Dim strDate, strCustom, strPageViews, strClicks, fltCtr, fltEarnings, fltEpc, fltEcpm, fltQuality
 Dim arrDate, arrCustom
 
 
 'Do Until objFile.AtEndOfStream
     strLine   = objFile.ReadLine
     response.write(strLine)
     arrLine   = Split(strLine, ",")
     
     arrDate   = Split(arrLine(0), "/", 3) ' 12/31/2008
     strDate   = arrDate(2) & "-" & arrDate(0) & "-" & arrDate(1) ' 2008-12-31
     
     response.write(strDate)
 'Loop
 
 objFile.Close
 
 response.write("finito")
 %>


The "test.csv" is in the same folder then the ASP script above. The message output is always "D:\Webs\cli142\affiliate_test\admin\xyz\test.csv does not exist". In the FTP program, I see this server path: "/webroot/affiliate_test/admin/xyz". Is "webroot" a virtual directory? I just want to open a file by a script that is in the same directory :(

Thanks in advance,
Chris
 
#1
    Chriz

    • Total Posts : 2
    • Scores: 0
    • Reward points : 0
    • Joined: 7/29/2008
    • Status: offline
    RE: OpenTextFile Wednesday, July 30, 2008 10:02 AM (permalink)
    0
    Hm it took me a while to find out that "On Error Resume Next" must be removed to see the error messages.
    This forum is kind of strange, no answer for that beginner problem, but no.1 on "vbscript forum" in Google.
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9