---
title: "fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:onCancellation:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/fileexporter(ispresented:document:contenttype:defaultfilename:oncompletion:oncancellation:)"
---

# fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:onCancellation:)

Presents a system dialog for allowing the user to export a WritableDocument to a file on disk.

## Declaration

```swift
nonisolated func fileExporter<D>(isPresented: Binding<Bool>, document: D?, contentType: UTType? = nil, defaultFilename: String? = nil, onCompletion: @escaping (Result<URL, any Error>) -> Void, onCancellation: (() -> Void)? = nil) -> some View where D : WritableDocument, D.Writer.Destination == URL

```

## Parameters

- `isPresented`: A binding to whether the dialog should be shown.
- `document`: The in-memory document to export.
- `contentType`: The content type to export to. If not provided, WritableDocument.writableContentTypes are used.
- `defaultFilename`: If provided, the default name to use for the exported file, which the user will have an opportunity to edit prior to the export.
- `onCompletion`: A callback that will be invoked when the operation has succeeded or failed. The result indicates whether the operation succeeded or failed.
- `onCancellation`: A callback that will be invoked if the user cancels the operation.

## Discussion

Discussion In order for the dialog to appear, document must be non-nil. When the operation is finished, isPresented will be set to false before onCompletion is called. If the user cancels the operation, isPresented will be set to false and onCancellation will be called.

## See Also

### Exporting to file

- [fileExporter(isPresented:document:contentType:defaultFilename:onCompletion:)](swiftui/view/fileexporter(ispresented:document:contenttype:defaultfilename:oncompletion:).md)
- [fileExporter(isPresented:documents:contentType:onCompletion:)](swiftui/view/fileexporter(ispresented:documents:contenttype:oncompletion:).md)
- [fileExporter(isPresented:document:contentTypes:defaultFilename:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:document:contenttypes:defaultfilename:oncompletion:oncancellation:).md)
- [fileExporter(isPresented:documents:contentTypes:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:documents:contenttypes:oncompletion:oncancellation:).md)
- [fileExporter(isPresented:item:contentTypes:defaultFilename:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:item:contenttypes:defaultfilename:oncompletion:oncancellation:).md)
- [fileExporter(isPresented:items:contentTypes:onCompletion:onCancellation:)](swiftui/view/fileexporter(ispresented:items:contenttypes:oncompletion:oncancellation:).md)
- [fileExporterFilenameLabel(_:)](swiftui/view/fileexporterfilenamelabel(_:).md)
