- Home /
File Save Location (PC, Mac, iOS, Android, etc)
I'm trying to save a screenshot to file and need some help on exactly how to save it where I want to save it.
Here's just a snippet of my relevant code (mostly copied straight from the Docs). Just trying to save a Texture2D as a PNG file:
var bytes = selectedPicture.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);
I want the file to save to the following locations depending on platform: Windows and Mac - Pictures iOS and Android - Don't care as long as it can be quickly viewed from the respective Image Gallery. I know Android is more lenient on where you put files and will create a new folder in your Gallery for each folder in the file system. Less sure about iOS on how that's handled. Windows Phone - I don't have one to test yet but basically same as iOS/Android.
So what would I do for each platform?
Answer by Vander-Horn · Jul 20, 2017 at 05:12 PM
The file path is different depending on the OS, however every os has a myDocuments folder, and that is a common place for saving files. There are a few other options to choose from.
In order to get your OS' mydocuments folder simply us
string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
use Path.Combine method to join to paths with the system appropriate symbol
string path = Path.Combine(path, "myApplicationName", "ScreenShot.png");
Path.Combine docs: https://msdn.microsoft.com/en-us/library/dd784047(v=vs.110).aspx
stackoverflow post detailing other options for special folders.
Your answer
Follow this Question
Related Questions
Can you use WebCam for mobile devices? 1 Answer
Does PersistentDataPath get overwritten on mobile? 1 Answer
Problem Saving game progress 1 Answer