kartik k

kartik k

  • 1.6k
  • 181
  • 424

Need single control for save and opening a file in WPF

Nov 19 2019 12:18 AM
Assuming there will be only one (.log) file
Say if user selects the path ex:(c:\test) and if the .log file exist then it should return c:\test\xyz.log.
if file not exist then in the same control user should specify the file name and it should be saved in the path in .log extension.
The below is the code :
string logFileName = string.Empty;
FolderBrowserDialog fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
logFileName = CheckLogFile(fbd.SelectedPath);
else
return;
if (!string.IsNullOrEmpty(logFileName))
LogFileName = Path.Combine(fbd.SelectedPath, logFileName);
else
{
Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
if (sfd.ShowDialog() == true)
{
LogFileName = sfd.FileName;
}
}
Any help?

Answers (1)