Unable to attatch a csv file to mail in objective c

I'm using the following code to attach a csv file that is generated to mail composer.

NSString *recipient = @"tejanvm92@gmail.com";
NSArray *recipients = [NSArray arrayWithObjects:recipient, nil];

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"CSV Export"];
[mailViewController setToRecipients:recipients];
[mailViewController setMessageBody:@"" isHTML:NO];
mailViewController.navigationBar.tintColor = [UIColor blackColor];
NSData *myData = [NSData dataWithContentsOfFile:@"yourFileName.csv"];

[mailViewController addAttachmentData:myData

[self presentModalViewController:mailViewController animated:YES];

When the code runs.....the csv file is not attached to the mail properly.

But When I got the mail, it is empty. Could you please help me in finding the issue?


[NSData dataWithContentsOfFile:@"yourFileName.csv"]// its wrong way.

Please write full path of csv file Like if your csv file in Documents directory. then

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSString *csvFilePath = [documentsDirectory stringByAppendingFormat:@"/yourFileName.csv"];

after that change in your code

 [NSData dataWithContentsOfFile:csvFilePath];

Need Your Help

Get URL of a website at runtime

c# winforms url

Is there any way to get a URL from a website e.g goodreads.com at runtime. Because I am taking book name as input for getting book reviews from goodreads and I also have written a js function to co...

Asynchronous Twitter operations in an NSOperationQueue

ios objective-c twitter nsoperationqueue twrequest

To download a bunch of Twitter timelines, I created TWRequest objects in a loop and put them into an NSOperationQueue:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.