• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

cant load CSV into dataset - IE displays file does not exist, but it does - code supplied, prob small error

it's a simple task, use asp.net to load a csv file into a dataset.
the file exists : if i copy and paste the "c:\inetput\wwwroot\MyFolder\MyApp.csv" into browser, i access the file.
still i get the error file does not exist

i tried all the posts i could find, all of them use c# but the usage is the same.



    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        Dim MyConnection As System.Data.OleDb.OleDbConnection

        MyConnection = New System.Data.OleDb.OleDbConnection( _
        "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("/MyFolder/MyFile.csv") & ";Extended Properties=text")

        ' Select the data from Sheet1 of the workbook.
        MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)

        'DS = New System.Data.DataSet
        MyCommand.Fill(Extension1) '>>>>>>>> BOMBS OUT HERE
        MyConnection.Close()

        Me.DataGrid1.DataSource = Extension1
        Me.DataGrid1.DataBind()

    End Sub



Contents of CSV File : (No headers)
Barnabas,A,7528
Brains, Eric,7534


Please help me load this csv into dataset.
thanks!
0
jxharding
Asked:
jxharding
  • 6
  • 4
1 Solution
 
b1xml2Commented:
1. is the web server the same as your box?
2. Virtual directories means that the actual file location may not under wwwroot.


Server.MapPath("~/MyFolder.MyFile.csv")
do the trick.

0
 
b1xml2Commented:
correction.

If MyFolder is the web application then,

Server.MapPath("~/MyFile.csv");

If My Folder is accessible within the web application then

Server.MapPath("~/MyFolder/MyFile.csv");

The file should be within the current web application.

0
 
jxhardingAuthor Commented:
yes, the web server is my box


'c:\inetpub\wwwroot\MyFolder\MyFile.csv' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

but if i copy that section , i access the file.

this is a really non descriptive error message from asp.

so should the code work in fact then?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
b1xml2Commented:
Can the OLEDB Provider accept CSV files???
0
 
b1xml2Commented:
I dont think Jet can do that...
0
 
jxhardingAuthor Commented:
0
 
b1xml2Commented:
heh I was right:

  conn_excel_str = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq="
                + HttpContext.Current.Server.MapPath(".//" + csv_store_read);
        //Server.MapPath(".//" + csv_store_read)
        //Path mapped to csv file temp stored on the server

you load the csv through this driver not the Jet Driver
0
 
jxhardingAuthor Commented:
well its still not working

is there any other method of text that you could help me with to load this file into the dataset? i dont know how to se the darn microsoft text driver in a vb.net connection string.
0
 
jxhardingAuthor Commented:
This post did not help at all. I accepted answer because it is going to stand still. Im pursuing another question.
Thanks
0
 
b1xml2Commented:
i was researching the answer, i will post the answer nonetheless.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now