---
title: "importDocument(at:toParentItemIdentifier:completionHandler:)"
framework: fileprovider
role: symbol
role_heading: Instance Method
path: "fileprovider/nsfileproviderextension/importdocument(at:toparentitemidentifier:completionhandler:)"
---

# importDocument(at:toParentItemIdentifier:completionHandler:)

Imports a file or package into the given parent directory.

## Declaration

```swift
func importDocument(at fileURL: URL, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier, completionHandler: @escaping @Sendable (NSFileProviderItem?, (any Error)?) -> Void)
```

```swift
func importDocument(at fileURL: URL, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier) async throws -> NSFileProviderItem
```

## Parameters

- `fileURL`: A security-scoped URL for the file to import. Call doc://com.apple.documentation/documentation/Foundation/URL/startAccessingSecurityScopedResource() on the URL before accessing it and doc://com.apple.documentation/documentation/Foundation/URL/stopAccessingSecurityScopedResource() when finished.
- `parentItemIdentifier`: The persistent identifier for the directory where the item will be imported.
- `completionHandler`: A block that takes the following parameters:

## Discussion

Discussion important: You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration: func importDocument(at fileURL: URL, toParentItemIdentifier parentItemIdentifier: NSFileProviderItemIdentifier) async throws -> NSFileProviderItem For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously. This method is called when the user imports a document or directory. Override this method to move the file at the provided security-scoped URL to the file provider’s storage. Your implementation should return immediately. Call the completion handler before performing any network activity or other long-running tasks. Defer these tasks to the background. The importedDocumentItem instance that you pass to the completion handler must define the following properties: The user’s ability to import an item into a directory is controlled by the parent directory’s allowsAddingSubItems capability.

## See Also

### Handling actions

- [Providing support for user-driven actions](fileprovider/providing-support-for-user-driven-actions.md)
- [createDirectory(withName:inParentItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/createdirectory(withname:inparentitemidentifier:completionhandler:).md)
- [deleteItem(withIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/deleteitem(withidentifier:completionhandler:).md)
- [renameItem(withIdentifier:toName:completionHandler:)](fileprovider/nsfileproviderextension/renameitem(withidentifier:toname:completionhandler:).md)
- [reparentItem(withIdentifier:toParentItemWithIdentifier:newName:completionHandler:)](fileprovider/nsfileproviderextension/reparentitem(withidentifier:toparentitemwithidentifier:newname:completionhandler:).md)
- [setFavoriteRank(_:forItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/setfavoriterank(_:foritemidentifier:completionhandler:).md)
- [setLastUsedDate(_:forItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/setlastuseddate(_:foritemidentifier:completionhandler:).md)
- [setTagData(_:forItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/settagdata(_:foritemidentifier:completionhandler:).md)
- [trashItem(withIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/trashitem(withidentifier:completionhandler:).md)
- [untrashItem(withIdentifier:toParentItemIdentifier:completionHandler:)](fileprovider/nsfileproviderextension/untrashitem(withidentifier:toparentitemidentifier:completionhandler:).md)
