Write text filename as date in c#How do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Calling the base constructor in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?save page in c# webbrowser without savefiledialogue

What's the difference between 違法 and 不法?

Is there a word to describe the feeling of being transfixed out of horror?

MAXDOP Settings for SQL Server 2014

Is camera lens focus an exact point or a range?

Difference between -| and |- in TikZ

Translation of Scottish 16th century church stained glass

Can I use my Chinese passport to enter China after I acquired another citizenship?

Does the Mind Blank spell prevent the target from being frightened?

Why did the HMS Bounty go back to a time when whales are already rare?

Transformation of random variables and joint distributions

Has Darkwing Duck ever met Scrooge McDuck?

Why do IPv6 unique local addresses have to have a /48 prefix?

How can "mimic phobia" be cured or prevented?

Query about absorption line spectra

Why does Async/Await work properly when the loop is inside the async function and not the other way around?

Is possible to search in vim history?

Diode in opposite direction?

What linear sensor for a keyboard?

Greatest common substring

Is there a conventional notation or name for the slip angle?

If a character with the Alert feat rolls a crit fail on their Perception check, are they surprised?

Varistor? Purpose and principle

Why did the EU agree to delay the Brexit deadline?

Create all possible words using a set or letters



Write text filename as date in c#


How do I calculate someone's age in C#?What is the difference between String and string in C#?Hidden Features of C#?Calling the base constructor in C#Cast int to enum in C#How do you give a C# Auto-Property a default value?How do I enumerate an enum in C#?What are the correct version numbers for C#?How do I get a consistent byte representation of strings in C# without manually specifying an encoding?save page in c# webbrowser without savefiledialogue













0















So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code



private void btnAdd_Click(object sender, EventArgs e)

using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)

if (sfd.ShowDialog() == DialogResult.OK)


using (StreamWriter sw = new StreamWriter(sfd.FileName))

sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);






What I want to know is how I'm meant to preset the filename as a date in this code?










share|improve this question









New contributor




ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Have you already tried something?

    – dymanoid
    Mar 21 at 13:10











  • Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN

    – Simon Wilson
    Mar 21 at 13:11












  • if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it

    – Daniel Brughera
    Mar 21 at 14:14















0















So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code



private void btnAdd_Click(object sender, EventArgs e)

using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)

if (sfd.ShowDialog() == DialogResult.OK)


using (StreamWriter sw = new StreamWriter(sfd.FileName))

sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);






What I want to know is how I'm meant to preset the filename as a date in this code?










share|improve this question









New contributor




ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Have you already tried something?

    – dymanoid
    Mar 21 at 13:10











  • Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN

    – Simon Wilson
    Mar 21 at 13:11












  • if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it

    – Daniel Brughera
    Mar 21 at 14:14













0












0








0








So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code



private void btnAdd_Click(object sender, EventArgs e)

using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)

if (sfd.ShowDialog() == DialogResult.OK)


using (StreamWriter sw = new StreamWriter(sfd.FileName))

sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);






What I want to know is how I'm meant to preset the filename as a date in this code?










share|improve this question









New contributor




ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












So I've looked around for the answer and I'm just getting started with using c# so its probably simple, but I've got a block of code



private void btnAdd_Click(object sender, EventArgs e)

using (SaveFileDialog sfd = new SaveFileDialog() Filter = "TextDocuments)

if (sfd.ShowDialog() == DialogResult.OK)


using (StreamWriter sw = new StreamWriter(sfd.FileName))

sw.WriteLineAsync(txtMessage.Text);
MessageBox.Show("Your entry has been saved successfully!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);






What I want to know is how I'm meant to preset the filename as a date in this code?







c#






share|improve this question









New contributor




ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Mar 21 at 13:09









canton7

4,9061728




4,9061728






New contributor




ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Mar 21 at 13:08









ItsMeJoshItsMeJosh

1




1




New contributor




ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






ItsMeJosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Have you already tried something?

    – dymanoid
    Mar 21 at 13:10











  • Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN

    – Simon Wilson
    Mar 21 at 13:11












  • if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it

    – Daniel Brughera
    Mar 21 at 14:14

















  • Have you already tried something?

    – dymanoid
    Mar 21 at 13:10











  • Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN

    – Simon Wilson
    Mar 21 at 13:11












  • if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it

    – Daniel Brughera
    Mar 21 at 14:14
















Have you already tried something?

– dymanoid
Mar 21 at 13:10





Have you already tried something?

– dymanoid
Mar 21 at 13:10













Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN

– Simon Wilson
Mar 21 at 13:11






Set your SaveFileDialog's FileName property to the filename you wish...if it is to be a date then format the date as a filename. MSDN

– Simon Wilson
Mar 21 at 13:11














if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it

– Daniel Brughera
Mar 21 at 14:14





if you want to force the filename then remove the SaveFileDialog and use the streamwriter with your desired file name, if the user can only pick the folder use a FolderBrowserDialog instead, if not, will be confusing for the user if they change the defaultname and the program just ignore it

– Daniel Brughera
Mar 21 at 14:14












2 Answers
2






active

oldest

votes


















1














assign the current DateTime to DefaultFileName property on save file dialog instance



sfd.DefaultFileName=DateTime.Now.ToString();


or



sfd.FileName=DateTime.Now.ToString();





share|improve this answer























  • So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?

    – ItsMeJosh
    Mar 22 at 0:45











  • here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)

    – Aarif
    2 days ago


















0














 string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now); 
Console.WriteLine("Path: " + logPath);

using (StreamWriter file = new StreamWriter(@"./" + logPath, true))

file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));

Console.WriteLine("Logs inserted to file");





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281158%2fwrite-text-filename-as-date-in-c-sharp%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    assign the current DateTime to DefaultFileName property on save file dialog instance



    sfd.DefaultFileName=DateTime.Now.ToString();


    or



    sfd.FileName=DateTime.Now.ToString();





    share|improve this answer























    • So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?

      – ItsMeJosh
      Mar 22 at 0:45











    • here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)

      – Aarif
      2 days ago















    1














    assign the current DateTime to DefaultFileName property on save file dialog instance



    sfd.DefaultFileName=DateTime.Now.ToString();


    or



    sfd.FileName=DateTime.Now.ToString();





    share|improve this answer























    • So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?

      – ItsMeJosh
      Mar 22 at 0:45











    • here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)

      – Aarif
      2 days ago













    1












    1








    1







    assign the current DateTime to DefaultFileName property on save file dialog instance



    sfd.DefaultFileName=DateTime.Now.ToString();


    or



    sfd.FileName=DateTime.Now.ToString();





    share|improve this answer













    assign the current DateTime to DefaultFileName property on save file dialog instance



    sfd.DefaultFileName=DateTime.Now.ToString();


    or



    sfd.FileName=DateTime.Now.ToString();






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 21 at 13:20









    AarifAarif

    368413




    368413












    • So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?

      – ItsMeJosh
      Mar 22 at 0:45











    • here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)

      – Aarif
      2 days ago

















    • So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?

      – ItsMeJosh
      Mar 22 at 0:45











    • here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)

      – Aarif
      2 days ago
















    So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?

    – ItsMeJosh
    Mar 22 at 0:45





    So im not sure if ive done it correctly but ive editted the code to this using (StreamWriter sw = new StreamWriter(sfd.FileName = DateTime.Now.ToString())) but its still not working, the rest of the code is still the same as the original post im just wondering what else i should've done?

    – ItsMeJosh
    Mar 22 at 0:45













    here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)

    – Aarif
    2 days ago





    here's an example from MSDN (docs.microsoft.com/en-us/dotnet/api/…)

    – Aarif
    2 days ago













    0














     string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now); 
    Console.WriteLine("Path: " + logPath);

    using (StreamWriter file = new StreamWriter(@"./" + logPath, true))

    file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));

    Console.WriteLine("Logs inserted to file");





    share|improve this answer



























      0














       string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now); 
      Console.WriteLine("Path: " + logPath);

      using (StreamWriter file = new StreamWriter(@"./" + logPath, true))

      file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));

      Console.WriteLine("Logs inserted to file");





      share|improve this answer

























        0












        0








        0







         string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now); 
        Console.WriteLine("Path: " + logPath);

        using (StreamWriter file = new StreamWriter(@"./" + logPath, true))

        file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));

        Console.WriteLine("Logs inserted to file");





        share|improve this answer













         string logPath = string.Format("0:yyyy-MM-dd.txt", DateTime.Now); 
        Console.WriteLine("Path: " + logPath);

        using (StreamWriter file = new StreamWriter(@"./" + logPath, true))

        file.Write(string.Format("0 1 2 3", DateTime.Now, log, Environment.NewLine, bankLog));

        Console.WriteLine("Logs inserted to file");






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 21 at 13:47









        Mert AkkanatMert Akkanat

        1




        1




















            ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.












            ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.











            ItsMeJosh is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid …


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281158%2fwrite-text-filename-as-date-in-c-sharp%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?