Change contents of TextAsset

I'm writing a custom editor that I want to edit TextAsset contents. What I have right now is a reference to a TextAsset, and what I would love to do is edit textAsset.text, and then call EditorUtility.SetDirty(textAsset) to write the changes to disk. Unfortunately, testAsset.text is readonly. I can't figure out a way to convert from a TextAsset to a system file path, either. Does anyone know how to do this? Any way that I could figure out the local file path of an object selected in the Project panel would be helpful as well.


Though it has been late, but I want to share a quick solution for this question:

File.WriteAllText(AssetDatabase.GetAssetPath(TEXT_ASSET), STRING);

It should do the trick. Remember to add using System.IO;

I was not 100% clear if you were talking about editing the text asset from inside the editor or not. The below information is for modifying files on a run-time build (I did see that your tags included the editor)...

As far as I know the TextAssets are compiled into the same assets files as your other content; which means once the application is deployed it would be compiled into something that looks like this "sharedassets0.assets". There would be no easy way to change the text asset directly without some clever file manipulation.

An easier option would be to maybe store your text assets in another directory local to your project and instead of visually linking them up as assets you would just use the .NET IO API to load the text dynamically and then you could easily save any text changes you needed back to that file. This solution would prevent you from visibly linking them in the editor, but if you needed to assign them in the editor the easiest way would be to just have a string field where you put the file name for the text file and then your application would use that filename when loading your file from code.