Question

I am making a program where the user is asked to enter a world name and a author name. When he clicks finish a saveFileDialog is opened and asks the user to choose a save location. But I want it to automatically enter the name of the world the user entered as file name. But leave the user free to alter it. Is this possible and how can I do it.

Here is my save code, the saveFileDialog is on JSON filter setting.

//Saving the project
if (saveWork.ShowDialog() == DialogResult.OK)
{
string output = JsonConvert.SerializeObject(MainForm.CurrentWorld);
try
{
string name = saveWork.FileName;
using (System.IO.StreamWriter sw = new StreamWriter(name))
sw.WriteLine(output);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Était-ce utile?

La solution

Just set the FileName property before showing the dialog.

Autres conseils

 SaveFileDialog saveFileDialog = new SaveFileDialog();
 saveFileDialog.InitialDirectory = @"yourDir "; 
 saveFileDialog.FileName = "yourFileName";
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top