Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
converto datetime always changes format 9 37
What can cause the styling on a .NET site to not be found? 17 26
Cant save 3D 4 21
VB.Net - MemoryMappedFiles - Confirm receipt 2 19
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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