Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.


Any help?

What I have tried:

Below is the code :
C#
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;
                }
            }
Posted
Updated 18-Nov-19 21:48pm
v2

1 solution

I may be missing something, but what you are describing is exactly what a SaveFileDialog provides.
Besides, why are you using a Microsoft.Win32.SaveFileDialog instead of a System.Windows.Forms.SaveFileDialog?
SaveFileDialog Class[^]
SaveFileDialog Component (Windows Forms)[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900