---
title: "beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nssavepanel/beginsheetfordirectory:file:modalforwindow:modaldelegate:didendselector:contextinfo:"
---

# beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:

Presents a Save panel as a sheet with a specified path and, optionally, a specified file in that path.

## Declaration

```occ
- (void) beginSheetForDirectory:(NSString *) path file:(NSString *) name modalForWindow:(NSWindow *) docWindow modalDelegate:(id) delegate didEndSelector:(SEL) didEndSelector contextInfo:(void *) contextInfo;
```

## Parameters

- `path`: Directory whose files the panel displays. When nil, the directory is the same directory used in the previous invocation of the panel; this is probably the best choice for most situations.
- `name`: Specifies a particular file in path that is selected when the Save panel is presented to a user. When nil, no file is initially selected.
- `docWindow`: If not nil, the Save panel slides down as a sheet running as a document modal window in docWindow. If nil, the behavior defaults to a standalone modal window.
- `delegate`: This is not the same as a delegate assigned to the panel. This delegate is temporary and the relationship only lasts until the panel is dismissed. The NSSavePanel object has a weak reference to the modal delegate.
- `didEndSelector`: Message sent to modalDelegate after the modal session has ended, but before dismissing the Save panel. didEndSelector may dismiss the Save panel itself; otherwise, it is dismissed on return from the method. The corresponding method should have the following signature: - (void)savePanelDidEnd:(NSSavePanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo; The value passed as returnCode is either NSCancelButton or NSOKButton.
- `contextInfo`: Context information passed to modalDelegate in the didEndSelector message.

## See Also

### Related Documentation

- [beginSheetModal(for:completionHandler:)](appkit/nssavepanel/beginsheetmodal(for:completionhandler:).md)

### Methods

- [allowedFileTypes](appkit/nssavepanel/allowedfiletypes.md)
- [requiredFileType](appkit/nssavepanel/requiredfiletype.md)
- [setRequiredFileType:](appkit/nssavepanel/setrequiredfiletype:.md)
- [setDirectory:](appkit/nssavepanel/setdirectory:.md)
- [runModalForDirectory:file:](appkit/nssavepanel/runmodalfordirectory:file:.md)
- [panel:compareFilename:with:caseSensitive:](objectivec/nsobject-swift.class/panel:comparefilename:with:casesensitive:.md)
- [panel:isValidFilename:](objectivec/nsobject-swift.class/panel:isvalidfilename:.md)
- [panel:shouldShowFilename:](objectivec/nsobject-swift.class/panel:shouldshowfilename:.md)
- [panel:directoryDidChange:](objectivec/nsobject-swift.class/panel:directorydidchange:.md)
- [directory](appkit/nssavepanel/directory.md)
- [filename](appkit/nssavepanel/filename.md)
- [selectText:](appkit/nssavepanel/selecttext:.md)
