5

Does anyone know how to get the path to the tmp directory in iOS 8 with Xamarin?

testing
  • 19,681
  • 50
  • 236
  • 417
  • Can you explain the downvote? E.g. giving an answer? Is there something like `var caches = Path.Combine (NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User) [0].Path, "Caches");`? – testing Apr 30 '15 at 12:36
  • 2
    No idea why there was a downvote, just voted your question up ;-). – asp_net Apr 30 '15 at 13:07

3 Answers3

7

Just try:

var documents = NSFileManager.DefaultManager
    .GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User)[0].Path;

var tmp = Path.Combine(documents, "../", "tmp");
asp_net
  • 3,567
  • 3
  • 31
  • 58
  • Thanks. I'll try it. One question though: Will this the real `tmp` directory or a subdirectory of the `Documents` directory (which can be made available to the user through iTunes file sharing and will be backed up)? – testing Apr 30 '15 at 13:10
  • Interesting. He makes this path `/Documents/../tmp/test.jpg`. Through `..` he is in the correct path. – testing Apr 30 '15 at 13:23
  • Was wondering about that strange path lately, too. For a detailed overview see http://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system/ – asp_net Apr 30 '15 at 13:47
6

You can just use

var tmp = System.IO.Path.GetTempPath ();

This will return your app's tmp directory

dalexsoto
  • 3,412
  • 1
  • 27
  • 43
1
//https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_the_file_system
public string TempPath()
{           
    var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    var ret = Path.Combine(documents, "..", "tmp");
    return ret;
}
gre_gor
  • 6,669
  • 9
  • 47
  • 52