Document package

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

  1. macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    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:mad:"%@/%@",fileName,@"test"]
    atomically:0];
    return YES;
    }
     
  2. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #2
    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. thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #3
    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. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #4
    Do you have permission to write to that folder?
     

Share This Page