PDA

View Full Version : Document package




MrFusion
Jun 29, 2006, 09:37 AM
Hey,

I am trying to save a document as a package. As a test I wanted to save a plaintext file inside a directory. So I created a new project (cocoa document based) and added to following code (see below).
I also edited the target to set the name, extensions and such.

But when I try to save, I still get a sheet saying this is not possible. No files are actually saved either.
I would prefer not to use filewrapper (save everything in once), as my program will increasingly add files to the package, but will not edit them
afterwards.

Thanks.
PS. I tried google, but couldn't find anything useful for me. I did find the same question, but alas without an answer.

- (BOOL)writeToFile:(NSString *)fileName ofType:(NSString *)docType
{
NSLog(@"%@",docType);
NSString *str = @"qwerty";
NSData *mydata = [str dataUsingEncoding:NSUTF8StringEncoding];
[mydata writeToFile:[NSString stringWithFormat:@"%@/%@",fileName,@"test"]
atomically:0];
return YES;
}



iSee
Jun 29, 2006, 12:12 PM
I'm not sure, but here is one thing to check:

Will your sample code work if the folder already exists? I'm wondering if it is failing because the file you are trying to write to is in a folder that doesn't exist.

If it works when the folder already exists, then you can modify your code so that it first checks to see if the folder exists and create it if it doesn't.

Good luck :)

MrFusion
Jun 30, 2006, 01:43 AM
I'm not sure, but here is one thing to check:

Will your sample code work if the folder already exists? I'm wondering if it is failing because the file you are trying to write to is in a folder that doesn't exist.

If it works when the folder already exists, then you can modify your code so that it first checks to see if the folder exists and create it if it doesn't.

Good luck :)

If the folder exist, it can be opened. It does disappear when trying to overwrite it.
Checking to see if the folder needs to be created before writing to it says that it is present. However, the fileName passed to the method is some temporary one and not the location I specified. It is a folder located somewhere in /private/var/tmp/....

caveman_uk
Jun 30, 2006, 02:44 AM
It is a folder located somewhere in /private/var/tmp/....
Do you have permission to write to that folder?