agupta
agupta

Reputation: 403

How to save filename with space on Iphone

I am trying to save file in document directory using

NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES) lastObject];
NSString *filename=[NSString stringWithFormat:@"abc 1.pdf",];
NSString *pdfLocation = [documentDirectory stringByAppendingPathComponent:filename];

I am opening this file using a web view

NSURL *url = [NSURL URLWithString:pdfLocation];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:url];
[self.webView loadRequest:urlRequest];
[urlRequest release];

This fails if the the file name has a space.How should I save file so that space in the filename is maintained.

Upvotes: 2

Views: 180

Answers (1)

Akshay
Akshay

Reputation: 5765

UIWebView expects a file URL in this case. Change the line to:

NSURL *url = [NSURL fileURLWithPath:pdfLocation];

Upvotes: 3

Related Questions