Link to home
Start Free TrialLog in
Avatar of Adnan
AdnanFlag for Norway

asked on

How do i save file with filename, Date and time. using windows form SaveFileDialog

Hi

I want to create or save files with filename ,date, time....can some one help me with this?


Stream myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
 
            //saveFileDialog1.Filter = "txt files (*.xml)|*.xml(*.txt)|*.txt|All files (*.*)|*.*";
            saveFileDialog1.Filter = "File Type (*.xml)|*.xml";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;
            saveFileDialog1.FileName = txtBackupFile.Text;
           
            DateTime currentDateTime = DateTime.Now;
            String dateStr = currentDateTime.ToString("yyyy-MM-dd HH_mm_ss");
 
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    // Code to write the stream goes here.
                    //this.lblBackupPath.Text = "c:\tmp";
                    txtBackupFilePath.Text = saveFileDialog1.FileName.Substring(dateStr);
                    myStream.Close();
                }
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial