Document package

Discussion in 'Mac Programming' started by MrFusion, Jun 29, 2006.

  1. MrFusion macrumors 6502a

    Jun 8, 2005

    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

    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
    NSString *str = @"qwerty";
    NSData *mydata = [str dataUsingEncoding:NSUTF8StringEncoding];
    [mydata writeToFile:[NSString stringWithFormat:mad:"%@/%@",fileName,@"test"]
    return YES;
  2. iSee macrumors 68040


    Oct 25, 2004
    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 :)
  3. MrFusion thread starter macrumors 6502a

    Jun 8, 2005
    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/....
  4. caveman_uk Guest


    Feb 17, 2003
    Hitchin, Herts, UK
    Do you have permission to write to that folder?

Share This Page