0
 NSString *dateString= [self currentDateandTime];

//create file path and file name

  NSString *docDirectory =
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *pdfPath = [docDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"602_TW0023.%@_pdf.pdf",dateString]];
NSLog(@"Path: %@", pdfPath);

i converted an image to pdf and saved it with current date and time. How can i use this file to upload to ftp or php.

NSString* theFileName = [pdfPath lastPathComponent];

how to call above string into other method.can we set tag or what? i'm new to programming. point me right direction.

i tried a lot.

NSString *applicationDocumentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filepath =[NSString stringWithFormat: @"%@/%@",applicationDocumentsDir, @"%@"];

NSData *uploadData = [NSData dataWithContentsOfFile: filepath];
Avis
  • 505
  • 4
  • 14
  • you can create a singleton or global variable, or you can get the names of all the files in the DocumentsDirectory and sort them by date. [link to question about getting names of files in directory](http://stackoverflow.com/questions/6398937/getting-a-list-of-files-in-the-resources-folder-ios) – Ignacy Debicki Aug 20 '14 at 16:25
  • thanks for reply. but i dont need to list. because those files are temporary files.my app handles only one file at a time – Avis Aug 20 '14 at 16:28
  • is there any way to select file with it's extension? @IgnacyDebicki – Avis Aug 20 '14 at 16:30
  • if you are handling one file at a time, you can always set a property of one of the classes as NSString that contains the filename – Ignacy Debicki Aug 20 '14 at 16:30
  • i tried that, seriously but it didn't work for me.i set a property for file that i'm creating and i tried to retrieve..but i'm missing some logic @IgnacyDebicki – Avis Aug 20 '14 at 16:34
  • can you post some code of how you have been trying to pass the filename – Ignacy Debicki Aug 20 '14 at 16:38
  • ,i did can u check it out?@IgnacyDebicki,http://stackoverflow.com/q/25396214/3923716,this is also my question same topic, u can see my code here – Avis Aug 20 '14 at 16:43
  • also, if you are handling only one file at a time and then delete it, can't you use a static filename like "image.pdf"? – Ignacy Debicki Aug 20 '14 at 16:55

1 Answers1

0

in your class.h:

 @property(strong,nonatomic)NSString *filepath;

when you create the file path add:

self.filepath=pdfPath;

Then, when creating the data to upload use:

NSData *uploadData =[NSData dataWithContentsOfFile:self.filepath];

this will make sure you have the same file path when saving and reading the pdf

Ignacy Debicki
  • 437
  • 4
  • 18