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


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);

Open in new window

Who is Participating?
philipjonathanConnect With a Mentor Commented:
You can insert at line 17:

StreamWriter writer = new StreamWriter(myStream);
writer.Write("Hello World"); // your data here

And before line 20:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.