- Home /
Write to xml file in after build
void SaveClassToFile()
{
XmlSerializer serializer = new XmlSerializer(typeof(Class[]));
StreamWriter writer = new StreamWriter(Path.Combine(Application.dataPath ,"classes.xml"));
writer.Flush();
serializer.Serialize(writer,_classes);
writer.Close();
}
I saw that my code above do not work when i build the game. So i moved the "classes.xml" file to the resource folder but i do not know how do write to this file now. If you know any tips or how i should continue. Please let me know. Thanks!
Do you mean it's not working in the running game or you want this script to run after you hit Build on the File menu?
It worked fine when i had the files in the assets folder. But i was unable to read or write to the file when i build the game and run it from the .exe file.
I managed to read the file from the resource folder. But i do not know how to write to the file if i would put it in the resource folder. The code above is how i used to read the file from the assets folder.
Your answer
Follow this Question
Related Questions
C# Getting only the Name of the XML File and not the Directory of the XML File 2 Answers
Why XmlTextReader become so slowly in Unity? 0 Answers
How do i load Xml and assign variables to player in C#? 1 Answer
Opening XML file which determines the game 0 Answers
StreamWriter problems in Unity 5? 0 Answers