title: Save file in a different location in iPhone App
body: <p>I have a problem.
  My proget create a xml file.
  In the iPhone this file was store in the NSDocumentDirectory.
  I wanna save this file in another directory like Desktop(where there are the apps) or another visible folder.
  Thanks.</p>
  
  <p>This is my code:</p>
  
  <pre><code>-(void)saveInXML:(NSString*)name:(float)x:(float)y:(float)z{
  
      //NSDocumentDirectory put the file in the app directory
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES);
      NSString *documentsDirectoryPath = [paths objectAtIndex:0];
      NSString *filePath = [documentsDirectoryPath  stringByAppendingPathComponent:@"filePosizioni.xml"];
  
      NSFileHandle *myHandle;
      NSFileManager *fileManager = [NSFileManager defaultManager];
  
      NSString *titoloXML = [NSString stringWithFormat:@"File Xml delle posizioni del iPhone"];
      NSString *inizioTag = [NSString stringWithFormat:@"\n\n\n&lt;posizione&gt;"];
      NSString *tagName = [NSString   stringWithFormat:@"\n &lt;name&gt;%@&lt;/name&gt;", name];
      NSString *tagX = [NSString  stringWithFormat:@"\n  &lt;x&gt;%f&lt;/x&gt;", x];
      NSString *tagY = [NSString  stringWithFormat:@"\n  &lt;y&gt;%f&lt;/y&gt;", y];
      NSString *tagZ = [NSString  stringWithFormat:@"\n  &lt;z&gt;%f&lt;/z&gt;", z];
      NSString *fineTag= [NSString    stringWithFormat:@"\n&lt;/posizione&gt;"];
  
      NSData* dataTitoloXML = [titoloXML dataUsingEncoding: NSASCIIStringEncoding];
      NSData* dataInizioTag = [inizioTag dataUsingEncoding: NSASCIIStringEncoding];
      NSData* dataName = [tagName dataUsingEncoding: NSASCIIStringEncoding];
      NSData* dataX = [tagX dataUsingEncoding: NSASCIIStringEncoding];
      NSData* dataY = [tagY dataUsingEncoding: NSASCIIStringEncoding];
      NSData* dataZ = [tagZ dataUsingEncoding: NSASCIIStringEncoding];
      NSData* dataFineTag = [fineTag dataUsingEncoding: NSASCIIStringEncoding];
  
      if(![fileManager fileExistsAtPath:filePath])
          [fileManager createFileAtPath:filePath  contents:dataTitoloXML attributes:nil];
  
      myHandle  = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
  
      [myHandle seekToEndOfFile];
      [myHandle   writeData:dataInizioTag];
      NSLog(@"writeok");
  
      [myHandle seekToEndOfFile];
      [myHandle   writeData:dataName];
      NSLog(@"writeok");
  
      [myHandle seekToEndOfFile];
      [myHandle   writeData:dataX];
      NSLog(@"writeok");
  
      [myHandle seekToEndOfFile];
      [myHandle   writeData:dataY];
      NSLog(@"writeok");
  
      [myHandle seekToEndOfFile];
      [myHandle   writeData:dataZ];
      NSLog(@"writeok");
  
      [myHandle seekToEndOfFile];
      [myHandle   writeData:dataFineTag];
      NSLog(@"writeok");
  
      [myHandle seekToEndOfFile];
  
      NSLog(@"zp26 %@",filePath);
  
  
  }
  </code></pre>