# SaveFileDialog

This class can either open and overwrite an existing file or create a new file.

Most of the functionality for this class is found in the `FileDialog` class.

{% hint style="info" %}
For a full list of properties, methods and events see the [API documentation.](http://docs.wisej.com/api)
{% endhint %}

## Features

### Filtering

The SaveFileDialog filters files shown to the user based on a given pattern. For example, the filter `Image Files|*.jpg|All files|*.*` will show files ending with .jpg by default. Users can modify the filter using the dropdown menu.

![SaveFileDialog showing image file type filtering options](https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2Fgit-blob-94e9aa9f3bd9ceaa5bc12a4ceebfc0b307def828%2Fimage.png?alt=media)

{% hint style="success" %}
The [FileDialog.FileName](https://docs.wisej.com/api/wisej.web/common-dialogs/wisej.web.filedialog#filename) property returns the virtual path relative to the root. To get the physical path on the server, use [FileDialog.MapPath()](https://docs.wisej.com/api/wisej.web/common-dialogs/wisej.web.filedialog#mappath-filepath).
{% endhint %}

### Check Existing Files

The SaveFileDialog validates file existence before saving to disk, helping prevent accidental file overwrites.

![SaveFileDialog showing file existence validation warning](https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2Fgit-blob-6c1d557a34a69bb4b443ddff6df4a3d6dda22d73%2Fimage.png?alt=media)

### Help

The SaveFileDialog includes an optional "?" (Help) tool for displaying navigation assistance.

![SaveFileDialog showing help button and navigation interface](https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2Fgit-blob-ede4e3ea300be1f3edfd22f37ff1c785def0daf7%2Fimage.png?alt=media)

## How To

### Connect to the File System

Add at least one `IFileSystemProvider` to the Roots collection before showing the dialog:

```csharp
//Using an absolute file path
SaveFileDialog filedialog = new SaveFileDialog(); 
filedialog.Roots.Add(new FileSystemProvider("C:\\", "Main_Directory"));
```

```csharp
//Using a relative file path
SaveFileDialog filedialog = new SaveFileDialog(); 
filedialog.Roots.Add(new FileSystemProvider("./", "Main_Directory"));
```

### Customize the Appearance

The SaveFileDialog supports customization of individual controls including textboxes and pickers.

To customize these controls:

1. Create a class inheriting from `FileDialogUI`
2. Add the custom `FileDialog` constructor
3. Modify the controls as needed

{% tabs %}
{% tab title="C#" %}

```csharp
public class CustomSaveFileDialogUI : FileDialogUI
{
    public CustomSaveFileDialogUI(SaveFileDialog saveFileDialog) : base(saveFileDialog)
    {
        this.HeaderBackColor = Color.DarkOrange;
        foreach (ColumnHeader col in this.listView.Columns)
        {
            col.BackColor = Color.DarkOrange;
        }
    }
}
```

{% endtab %}
{% endtabs %}

After applying the OpenFileDialog's `DialogTemplate` property to the new class, the result looks like this:

![Customized SaveFileDialog with dark orange theme applied](https://553579532-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MF1D11gPs_az3xaKusw%2Fuploads%2Fgit-blob-4e26881fe0dfb2d8a1f27d270fd62376a4b9f73d%2Fimage.png?alt=media)

For advanced customization of the `SaveFileDialog` using custom templates, see below.
