Problem loading XML files after build using .NET libraries


I am reading some text from an external XML. Everything works fine in the editor, but when 'I build & run' is not able to reach the files.

Here are the messages I got in the player log related to the problems: IsolatedStorageException: Could not find a part of the path "/Users/Alvaro/Desktop/Dropbox/proyectos unity/alfa06/"

The way I code this is like this:

var writer:XmlWriter = XmlWriter.Create(Application.dataPath.Substring(0, Application.dataPath.Length - 6)+file,settings);

var reader : StreamReader = File.OpenText(Application.dataPath.Substring(0, Application.dataPath.Length - 6)+file);

Please I need some help... I am getting a bit nervous if I can't solve this :S

And I got to read this thread:

KennyW: I can read an XML file from my data folder without problem. But my question here is how will I be able to read an XML file from inside my Unity3D resources (i.e. in the "project" tab or project "Hierarchy" instead of a file path?

dreamora: you can't

if you drop it into the project it will cease to be an xml (it will no longer exist as file in the build but will be part of the sharedassets.dll file), it will become a text asset where you can get the string from but only that.

Thnks in advance

Application.dataPath only ends with "Assets" (6 characters) when you run in the Editor. You shouldn't strip anything from the dataPath, just use it directly, and move your Xml files under your Assets folder.

You probably want to put the Xml files into your Resources folder to make sure they get included in the build.