I have a .cvs file inside a Resources folder. I am trying to use the FileHelpers .NET 2.0 library to load the file. It works fine in the Editor but not in the build. I’ve tried to change the path to just the file name but then it doesn’t seem to work in the editor.
You should be able to just load it as a TextAsset using Resources.Load(“filename”) as TextAsset; (don’t include the file extension)
I’m not familiar with FileHelpers, but once a project is built out, I don’t think the resources folder actually has a path.
You could also use streamingassets folder and thus use Application.streamingAssetsPath to get that path if needed.
Ah sorry. The FileHelpers class expect a file path.
Yeah, in that case it doesn’t work with the resource folder when built out as there is no resource folder. StreamingAssetsPath may not work either as some platforms can’t access it with a filepath (android, web platforms).
Is there a reason you need to use FileHelpers?
I use FileHelpers for a single method which is to load a csv file into a data table and read from it.
I guess I could replace it but it seems like it would be quite some work to parse the data table since it handles escaped commas as well.
Do you have the option to pass it a string and it will parse it and load it into a data table or does it only take a file path?
If you want a solution that will work on all platforms I’d strongly suggest just using a text asset (as mentioned above) and some other way to parse the string. There’s a tonne of c# CSV parsing code out there, should be trivial.
You don’t get standard file system access on a lot of platforms, so going that route is going to get messy.
Unfortunately no.
Hard to find some C# out there handles escaped commas, quotes, or newlines though.
This one looks pretty good: A Fast CSV Reader - CodeProject
Thanks. At first glance it seems like it requires a file path as well but I’ll try it when I have time.
It uses a StreamReader
which you can create from a string.
Just throw the file in the streaming assets folder. You can then read it out at runtime.