On Mar 21, 2012, at 8:19 PM, Paul Johnson wrote: > On closer examination, external contains nothing. Is this what it should > contain and if it isn't, does anyone have an example of how to set up a > directory on the SDCard I could have a look-see at? > > var external = GetExternalFilesDir(null); > if (!File.Exists(external + "\\myDir")) > { > System.IO.Directory.CreateDirectory(external + "\\myDir"); > }
The above will not work like you want it to work. It only compiles because `anything + "string"` is equivalent to `anything.ToString() + "string"`, so: string dir = external.ToString() + "\\myDir"; if (!File.Exists (dir)) ... "Fortunately", Java.IO.File.ToString() returns File.AbsolutePath. Unfortunately, File.AbsolutePath doesn't append a "/" for directories. The result is that `external + "\\myDir` is something like: /mnt/sdcard/Android/data/Scratch.ExternalStorage/files\mydir Note that '\' isn't a directory separator char on Linux, it is in fact a perfectly valid filename character, so you'll be trying to create the directory "files\myDir". Oddly, though, this works for me on the Xoom. $ adb shell ls /mnt/sdcard/Android/data/Scratch.ExternalStorage files files\mydir So I'm not sure why it fails for you, but it's certainly "weird", and further proof that "\\" should be avoided at all costs. Please use Path.Combine(), as jpobst suggested: var dir = Path.Combine (external.AbsolutePath, "myDir"); if (!File.Exists (dir)) ... - Jon _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid