# SaveFilePanel(string, string, string, string)

> Displays the "save file" dialog and returns the selected path name.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.6/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public static string SaveFilePanel(string title, string directory, string defaultName, string extension)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The title of the window to display.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The working directory that this dialog opens on.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The placeholder text to display in the "Save As" text field. This is the name of file to be saved.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The file extension to use in the saved file path. For example, enter "png" to save an image in the PNG format.

### Returns

| Type                                                           | Description                                                                                                |
| -------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| [string](https://learn.microsoft.com/dotnet/api/system.string) | A string path to the saved file if the dialog was canceled or the save failed, it returns an empty string. |

### Remarks

This function displays a dialog that prompts the user for a path to save an asset to. It does not create the file or parent directories. You are responsible for creating and writing to the file at the returned path location.

**Note:** The dialog has a Save button and a Cancel button. If you click the Cancel button, the window closes without saving.

Additional Resources: [EditorUtility.OpenFilePanel](/engine/6000.6/script-reference/unityeditor/editorutility/openfilepanel.md) function.

![EditorUtilitySaveFilePanel (SaveFilePanel(string, string, string, string))](/api/media?file=/engine/6000.6/media/images/EditorUtilitySaveFilePanel.png)

*Save File Panel.*

### Examples

```csharp
// Opens a file selection dialog for a PNG file and saves a selected texture to the file.

using UnityEditor;
using UnityEngine;
using System.IO;

public class EditorUtilitySaveFilePanel : MonoBehaviour
{
    [MenuItem("Examples/Save Texture to file")]
    static void Apply()
    {
        Texture2D texture = Selection.activeObject as Texture2D;
        if (texture == null)
        {
            EditorUtility.DisplayDialog(
                "Select Texture",
                "You Must Select a Texture first!",
                "OK");
            return;
        }

        var path = EditorUtility.SaveFilePanel(
            "Save texture as PNG",
            "",
            texture.name + ".png",
            "png");

        if (path.Length != 0)
        {
            var pngData = texture.EncodeToPNG();
            if (pngData != null)
                File.WriteAllBytes(path, pngData);
        }
    }
}
```
