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

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

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

## Declaration

```swift
nonisolated func fileExporter<D>(isPresented: Binding<Bool>, document: D?, contentTypes: [UTType] = [], defaultFilename: String? = nil, onCompletion: @escaping (Result<URL, any Error>) -> Void, onCancellation: @escaping () -> Void = {}) -> some View where D : FileDocument

```

## Parameters

- `isPresented`: A binding to whether the dialog should be shown.
- `document`: The in-memory document to export.
- `contentTypes`: The list of supported content types which can be exported. If not provided, FileDocument.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, isPresented must be true. 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. For example, a button that exports a document and handles cancellation might look like this: struct ExportButton: View {     @State private var isExporterPresented = false     var document: TextFile?

var body: some View {         Button("Export") {             isExporterPresented = true         }         .fileExporter(             isPresented: $isExporterPresented,             document: document,             contentTypes: [.utf8PlainText],             defaultFilename: "Exported Document"         ) { result in             switch result {             case .success(let url):                 print("Saved to \(url)")             case .failure(let error):                 print(error)             }         } onCancellation: {             print("Export cancelled")         }     } } To further configure the dialog’s appearance and behavior, use these view modifiers: fileDialogDefaultDirectory(_:), fileDialogConfirmationLabel(_:), fileDialogMessage(_:), fileDialogBrowserOptions(_:), fileExporterFilenameLabel(_:), and fileDialogCustomizationID(_:).
