0

I'm basically just trying to get a file path to save a file to but my SaveFileObject won't let me access the SelectedPath. I've checked the other forums and can't figure out why it won' tlet me, here's my code;

SaveFileDialog filePath = new SaveFileDialog();
 DialogResult result = filePath.ShowDialog();


     if (result == DialogResult.OK)
     {
         string folderPath = filePath.;
     }

It'll let me select filePath.ShowDialog again and filePath.ToString etc... Where am I going wrong?

James Morrison
  • 1,954
  • 2
  • 21
  • 48

1 Answers1

3

You actually want the file name from the FileName property from your SaveFileDialog. That will give you the full path and file name for the file your user wants to save.

SaveFileDialog saveDialog = new SaveFileDialog();
DialogResult result = saveDialog.ShowDialog();
if (result == DialogResult.OK)
{
    String fileName = saveDialog.FileName;
    //your code to save the file;
}

Although, since .ShowDialog() returns a DialogResult, you can use it directly in the if to spare one line of code (yup! I'm greedy)

Sirmyself
  • 1,464
  • 1
  • 14
  • 29