Domanda

I cannot seem to get OpenTextFile to open a CSV file on my server. I'm very new to ASP so apologies if this is a super simple question. I've got this code:

<%
dim fs,objTextFile
set fs=Server.CreateObject("Scripting.FileSystemObject")
set objTextFile = fs.OpenTextFile("my_file.csv")
%>

my_file.csv is in the same directory as the page that is running this code. I know the OpenTextFile line is causing an error because when I take that line out, the page runs but when I put it in, it doesn't. I've tried relative paths too starting with a '/' and writing the path out to the file but that doesn't work either. What am I doing wrong? Thanks so much for your help.

È stato utile?

Soluzione

I found the answer for anyone else who has this problem. In OpenTextFile you have to use server.mappath in order to get the file from the server. That line of code would look like this:

set objTextFile = fs.OpenTextFile(server.mappath("my_file.csv")
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top