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?

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: Path.Combine Method (System.IO) | Microsoft Learn

stackoverflow post detailing other options for special folders.