Importing CSV into DataGrid

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
cbarnhart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 48
Joined: Mon May 07, 2012 2:10 pm

Importing CSV into DataGrid

Post by cbarnhart » Mon Dec 31, 2012 8:45 pm

I am importing a csv into a datagrid. For testing I used

Code: Select all

on ReadDataFile
    answer file "Select a file"
   
   put URL ("file:" & it ) into tFileContents
   
   Put tFileContents into field "text" on Card "Database" 
   
   put line 1 of tFileContents into tColumnTitles    ## Creates Columns from the contents of the CSV's first line 
   replace comma with return in tColumnTitles
   set the dgProp["columns"] of group "AppData" on Card "Database" to tColumnTitles
   
   delete line 1 of tFileContents
   replace "," with tab in tFileContents
   Put tFileContents into field "text" on Card "Database" 
   set the dgText of group "AppData" on Card "Database" to tFileContents
end ReadDataFile
It worked perfect. Now I want to hard code the data location to a file located in the "/Data/info.csv" It will always be located in a sub-directory of the application

I have tried using the same convention as video or photos paths - But nothing worked
put URL ("file:/Data/info.csv") into tFileContents
put URL ("file:Data/info.csv") into tFileContents

I know this is simple but it is driving me crazy...Help

cbarnhart
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 48
Joined: Mon May 07, 2012 2:10 pm

Re: Importing CSV into DataGrid

Post by cbarnhart » Mon Dec 31, 2012 8:54 pm

Just figured out to use defaultFolder

Post Reply