Solved

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

Posted on 2008-06-24
1
545 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

12 Experts available now in Live!

Get 1:1 Help Now