question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SaveFileDialog does not append file extension to file name

See original GitHub issue

Describe the bug When saving a file with FilePickerSaveOptions or SaveFileDialog, the dialog doesn’t append the file extension to the user’s selected file name.

To Reproduce

var saveFileDialog = new SaveFileDialog
{
	Title = "Where to export Library",
	Filters = new()
	{
		new() { Name = "Excel Workbook (*.xlsx)", Extensions = new() { "xlsx" } }
	}
};

var fileName = await saveFileDialog.ShowAsync(this);
//fileName has no file extension

Expected behavior After the FilePickerSaveOptions and SaveFileDialog close, the user-selected file name should have the file extension of selected FileTypeChoices.

Desktop (please complete the following information):

  • OS: Windows
  • Version 11.0.0-preview4

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Mbucaricommented, Jan 4, 2023

The problem was with my patterns. I should have used the GLOB patterns like so:

new("Excel Workbook (*.xlsx)") { Patterns = new[] { "*.xlsx" } },
new("CSV files (*.csv)") { Patterns = new[] { "*.csv" } },
new("JSON files (*.json)") { Patterns = new[] { "*.json" } },
new("All files (*.*)") { Patterns = new[] { "*" } }
0reactions
Mbucaricommented, Dec 17, 2022

Here’s an example using StorageProvider.

var options = new FilePickerSaveOptions
{
	Title = "Where to export Library",
	SuggestedStartLocation =  new Avalonia.Platform.Storage.FileIO.BclStorageFolder(Configuration.Instance.Books),
	ShowOverwritePrompt = true,
	FileTypeChoices = new FilePickerFileType[]
	{
		new("Excel Workbook (*.xlsx)") { Patterns = new[] { "xlsx" } },
		new("CSV files (*.csv)") { Patterns = new[] { "csv" } },
		new("JSON files (*.json)") { Patterns = new[] { "json" } },
		new("All files (*.*)") { Patterns = new[] { "*" } },
	}
};

var selectedFile= await StorageProvider.SaveFilePickerAsync(options);

If I save a file without manually typing the file extension, selectedFile will not have the file extension, and I have no idea which FilePickerFileType the user selected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SaveFileDialog AddExtension doesn't work as expected
1 · I use the FilterIndex property to decide if I should store it as txt or xml file and not the extension...
Read more >
SaveFileDialog does not append file extension in ...
If user does not provide file name extension, the return value should be appended with file extension using the extension provided in ...
Read more >
SaveFileDialog Class (Microsoft.Win32)
Gets or sets a value indicating whether a file dialog automatically adds an extension to a file name if the user omits an...
Read more >
[REQUEST] Save File Dialog does not include file- ...
The current save file dialog will not automaticaly include a file-extension in some cases. Steps to reproduce the bug:
Read more >
How do I add filename, filter in saveitemdialog
I am using this code. SaveItemDialog tmpDestination = new SaveItemDialog() { Title = "ASCII Output file name", DefaultExt = "txt", Filter = "*....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found