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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript