<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDocument/writeToFile:ofType:originalFile:saveOperation:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDocument(im)writeToFile:ofType:originalFile:saveOperation:"
  },
  "title" : "writeToFile:ofType:originalFile:saveOperation:"
}
-->

# writeToFile:ofType:originalFile:saveOperation:

Writes the receiver document’s contents to a file.

```
- (BOOL) writeToFile:(NSString *) fullDocumentPath ofType:(NSString *) documentTypeName originalFile:(NSString *) fullOriginalDocumentPath saveOperation:(NSSaveOperationType) saveOperationType;
```

## Discussion

This method is called from [`writeWithBackupToFile:ofType:saveOperation:`](/documentation/AppKit/NSDocument/writeWithBackupToFile:ofType:saveOperation:) to actually write the file of type `docType` to `fullDocumentPath`. `fullOriginalDocumentPath` is the path to the original file if there is one and `nil` otherwise. The default implementation simply calls [`writeToFile:ofType:`](/documentation/AppKit/NSDocument/writeToFile:ofType:). You should not need to call this method directly, but subclasses that need access to the previously saved copy of their document while saving the new one can override this method. The `saveOperationType` argument is one of the constants listed in `Constants`.

See [`Document Saving Behavior`](/documentation/AppKit/NSDocument#Document-Saving-Behavior) for additional information about saving documents.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)