I’d like to write text to the file when the User specifies the save location, but this keeps returning an exception about unsupported file path. Where do I find the filepath?
private void SaveAs_Click(object sender, System.EventArgs e)
{
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
string createText = "Hello and Welcome" + Environment.NewLine;
string path = saveFileDialog1.ToString();
File.WriteAllText(path, createText);
myStream.Close();
}
}
}