Solved

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

Posted on 2008-06-24
1
548 Views
Last Modified: 2013-12-16
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

0
Comment
Question by:Adnan
1 Comment
 
LVL 18

Accepted Solution

by:
philipjonathan earned 500 total points
ID: 21863131
You can insert at line 17:

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


And before line 20:
writer.Close();
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now