x


How to load CSV files from webplayer

Yes, I realize that I could simply make the extension of my CSV file .TXT and use TextAsset to load it, however I do not want to do this. The CSV extension must remain as-is.

Basically I have a CSV file that I need to load and get the full text from. I can't use TextAsset because it's not a TXT file, and I've tried using Resources.Load(), however I'm not sure what type to cast it to.

How can I load a CSV file and access its contents? I tried using System.IO.StreamReader, and while this works in the editor, it does not work in the web player.

more ▼

asked Jun 04 '10 at 03:14 PM

Robert 1 gravatar image

Robert 1
364 17 18 25

Let me ask the obvious question, which I should have asked before :) Where is the file located?

Jun 05 '10 at 05:54 PM Cyclops

And a second question - why do you want to keep the .csv extension? Is there a specific need, say another program reads/writes it? Depending on the reason, there may also be a solution or work-around for that.

Jun 05 '10 at 06:07 PM Cyclops
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

To quote from: Best way to output data from Unity: "...not available in the webplayer for security reasons." The extension doesn't matter, the Browser simply isn't allowed to read or write to the local machine. You could either make your program a stand-alone executable, or put the datafile on the Server.

Update: to demonstrate this is an issue with the web-player, try building a standalone executable. Your System.IO.StreamReader code should read the file with no problem (assuming no bugs). Does that solve your problem?

If your answer is "no, I want the Browser to read the file", then sorry, it won't work.

Depending on the type of data, you might be able to use PlayerPrefs. Also see Does Unity have cookies? Since you appear to want a .csv file, probably not, but I thought I'd mention them.

more ▼

answered Jun 04 '10 at 04:04 PM

Cyclops gravatar image

Cyclops
7.1k 33 63 115

The question isn't about saving files, it's about loading them.

Jun 04 '10 at 04:39 PM Tetrad

It doesn't matter if it's about saving or loading, the web player cannot read or write to the disk at all, for security purposes. This isn't possible, and he'd have to make the game a standalone EXE.

Jun 04 '10 at 08:52 PM qJake

I know a little more background about this question than what's in the question. Basically the question should be "Can you use Resources.Load to load a file as a text asset that doesn't have the .txt extension". It's not about loading a file outside the unity bundle.

Jun 05 '10 at 04:52 PM Tetrad

But is it about loading a file from the webplayer? Because that's what is in the title :) A standalone executable can read any type of file using .Net http://System.IO. A Browser can not read anything from the user's hard drive, regardless of file type.

Jun 05 '10 at 05:42 PM Cyclops

This particular use case doesn't involve loading a file off the user's machine. The web player/streamreader stuff is a red herring that was intended to say "hey I tried doing it this way and found out it obviously doesn't work on the web player".

Jun 05 '10 at 05:53 PM Tetrad
(comments are locked)
10|3000 characters needed characters left

Unity Web player does not allow file manipulation(read or write). The best way to do this is using WWW in Unity to retrieve information from the file via PHP. Since CSV basically contains comma separated valued text, they can be passed echoed out as it is and on the unity side they can be split in an array using ',' (comma) delimiter. Let me know if you need more information or a sample code.

more ▼

answered Jun 20 '12 at 03:22 AM

dineshrajpurohit gravatar image

dineshrajpurohit
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x810
x434
x216
x12

asked: Jun 04 '10 at 03:14 PM

Seen: 2840 times

Last Updated: Jun 20 '12 at 03:22 AM