Path to my data file for Jet.OLEDB

E

Ed

I am using the following connection string to access a CSV file:

Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& path & ";Extended Properties=""Text;HDR=Yes;FMT=Delimited\"""

Then to load the data:

Dim conn As New OleDb.OleDbConnection(ConStr)

Dim daAllModels As New OleDb.OleDbDataAdapter("Select * from " & file,
conn)

daAllModels.Fill(dsAllModels, "TextFile")

The problem is "path" must be the full path to "file". I keep the
file in the same directory as the ASPX file that uses it. When I run
this on localhost I know the path to the file, but I do not know it
when I copy the project to my Internet host server. I can find the
current working directory on the host, but that is the Windows system
directory and I don't think I want to put the file there.

How can I specify the path?

thanks



Ed
 
F

Family Tree Mike

Ed said:
I am using the following connection string to access a CSV file:

Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
path & ";Extended Properties=""Text;HDR=Yes;FMT=Delimited\"""

Then to load the data:

Dim conn As New OleDb.OleDbConnection(ConStr)

Dim daAllModels As New OleDb.OleDbDataAdapter("Select * from " & file,
conn)

daAllModels.Fill(dsAllModels, "TextFile")

The problem is "path" must be the full path to "file". I keep the file in
the same directory as the ASPX file that uses it. When I run this on
localhost I know the path to the file, but I do not know it when I copy
the project to my Internet host server. I can find the current working
directory on the host, but that is the Windows system directory and I
don't think I want to put the file there.

How can I specify the path?

thanks



Ed


Use Server.MapPath("somefile.csv"). This returns the full path of the file
in the web app.
 
F

Family Tree Mike

Ed said:
I am using the following connection string to access a CSV file:

Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
path & ";Extended Properties=""Text;HDR=Yes;FMT=Delimited\"""

Then to load the data:

Dim conn As New OleDb.OleDbConnection(ConStr)

Dim daAllModels As New OleDb.OleDbDataAdapter("Select * from " & file,
conn)

daAllModels.Fill(dsAllModels, "TextFile")

The problem is "path" must be the full path to "file". I keep the file in
the same directory as the ASPX file that uses it. When I run this on
localhost I know the path to the file, but I do not know it when I copy
the project to my Internet host server. I can find the current working
directory on the host, but that is the Windows system directory and I
don't think I want to put the file there.

How can I specify the path?

thanks



Ed


Use Server.MapPath("somefile.csv"). This returns the full path of the file
in the web app.
 
M

Michel Posseth [MCP]

First of all i personally would group text files in a suitable sub directory
and not in the same path as the aspx page
second you should be able to access the file with it`s relative path in the
project structure if you have a hard way of finding this out then just type
a img source =
in the HTML editor and use the pick url wizard that appears , select the
file and the path that is appended by the wizard is your relative path to
the file

Third you might consider to ditch the jet oledb engine for text file parsing
as it is obsolete on 64 bit systems and thus you are limiting yourself
IMHO a better way of doing things is using system.io.text and a text parser
..


HTH

Michel
 
M

Michel Posseth [MCP]

First of all i personally would group text files in a suitable sub directory
and not in the same path as the aspx page
second you should be able to access the file with it`s relative path in the
project structure if you have a hard way of finding this out then just type
a img source =
in the HTML editor and use the pick url wizard that appears , select the
file and the path that is appended by the wizard is your relative path to
the file

Third you might consider to ditch the jet oledb engine for text file parsing
as it is obsolete on 64 bit systems and thus you are limiting yourself
IMHO a better way of doing things is using system.io.text and a text parser
..


HTH

Michel
 
E

Ed Sowell

Thanks, Mike.

When I set path:
path = Server.MapPath("ModelTable.csv")
the path looks OK except it omits the "/" separators. E.g., when run locally
I get
C:inetpubwwwrootJagModelsWebModelTable.csv.

What am I missing?

Ed
 
E

Ed Sowell

Thanks, Mike.

When I set path:
path = Server.MapPath("ModelTable.csv")
the path looks OK except it omits the "/" separators. E.g., when run locally
I get
C:inetpubwwwrootJagModelsWebModelTable.csv.

What am I missing?

Ed
 
E

Ed Sowell

Thanks, Michel.

I don't quite understand what you mean here:

a img source =

Are you saying to insert this into the generated HTML?

Ed
 
E

Ed Sowell

Thanks, Michel.

I don't quite understand what you mean here:

a img source =

Are you saying to insert this into the generated HTML?

Ed
 
F

Family Tree Mike

Ed Sowell said:
Thanks, Mike.

When I set path:
path = Server.MapPath("ModelTable.csv")
the path looks OK except it omits the "/" separators. E.g., when run
locally I get
C:inetpubwwwrootJagModelsWebModelTable.csv.

What am I missing?

Ed


Somehow it looks like it is using the \ as an escape sequence. How are you
writing the value out?
 
F

Family Tree Mike

Ed Sowell said:
Thanks, Mike.

When I set path:
path = Server.MapPath("ModelTable.csv")
the path looks OK except it omits the "/" separators. E.g., when run
locally I get
C:inetpubwwwrootJagModelsWebModelTable.csv.

What am I missing?

Ed


Somehow it looks like it is using the \ as an escape sequence. How are you
writing the value out?
 
M

Michel Posseth [MCP]

Well if you go to HTML view of a ASPX page and then insert a img source tag
<IMG SRC= as soon as you type the = sign a url picker will appear
 
M

Michel Posseth [MCP]

Well if you go to HTML view of a ASPX page and then insert a img source tag
<IMG SRC= as soon as you type the = sign a url picker will appear
 
E

Ed

You're right. I was writing it out with a script and it was a quoting
issue. The \'s were there.

But I've got it working. Here's what works:

Dim file As String = "ModelTable.csv"

Dim pathPlusFile As String = Server.MapPath(file)

Dim intPos As Integer = pathPlusFile.IndexOf(file)

Dim path As String = pathPlusFile.Substring(0, intPos)

Try

Dim f As System.IO.File

If f.Exists(pathPlusFile) Then

Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& path & ";Extended Properties=""Text;HDR=Yes;FMT=Delimited\"""

Dim conn As New OleDb.OleDbConnection(ConStr)

Dim daAllModels As New OleDb.OleDbDataAdapter("Select * from " & file,
conn)

daAllModels.Fill(dsAllModels, "TextFile")

Else

....

Thanks to all.

Ed
 
E

Ed

You're right. I was writing it out with a script and it was a quoting
issue. The \'s were there.

But I've got it working. Here's what works:

Dim file As String = "ModelTable.csv"

Dim pathPlusFile As String = Server.MapPath(file)

Dim intPos As Integer = pathPlusFile.IndexOf(file)

Dim path As String = pathPlusFile.Substring(0, intPos)

Try

Dim f As System.IO.File

If f.Exists(pathPlusFile) Then

Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
& path & ";Extended Properties=""Text;HDR=Yes;FMT=Delimited\"""

Dim conn As New OleDb.OleDbConnection(ConStr)

Dim daAllModels As New OleDb.OleDbDataAdapter("Select * from " & file,
conn)

daAllModels.Fill(dsAllModels, "TextFile")

Else

....

Thanks to all.

Ed
 
A

Andrew Morton

Ed said:
But I've got it working. Here's what works:

Dim file As String = "ModelTable.csv"

Dim pathPlusFile As String = Server.MapPath(file)

You'll want to use file="~/ModelTable.csv" if it's in the root folder of the
web site, just in case you call it from a page in a subdirectory.

Andrew
 
A

Andrew Morton

Ed said:
But I've got it working. Here's what works:

Dim file As String = "ModelTable.csv"

Dim pathPlusFile As String = Server.MapPath(file)

You'll want to use file="~/ModelTable.csv" if it's in the root folder of the
web site, just in case you call it from a page in a subdirectory.

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top