<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSPasteboard/writeFileContents(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPasteboard(im)writeFileContents:"
  },
  "title" : "writeFileContents(_:)"
}
-->

# writeFileContents(_:)

Writes the contents of the specified file to the pasteboard.

```
func writeFileContents(_ filename: String) -> Bool
```

## Parameters

`filename`

The name of the file to write to the pasteboard.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> if the data was successfully written, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Discussion

Writes the contents of the file `filename` to the receiver and declares the data to be of type `NSFileContentsPboardType` and also of a type appropriate for the file’s extension (as returned by the `NSCreateFileContentsPboardType` function when passed the files extension), if it has one.

## See Also

[`-  readFileContentsType:toFile:`](/documentation/AppKit/NSPasteboard/readFileContentsType(_:toFile:))

Reads data representing a file’s contents from the receiver and writes it to the specified file.



---

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)