Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C# how do i write a folder from a form

Options
  • 31-03-2012 1:51pm
    #1
    Registered Users Posts: 620 ✭✭✭


    Hi Guys,

    I have a forms application written in C# via a textbox i am writing to a flat file at a directory i have hardcoded as in i have to install it separate manually to disc for for the file writing and reading to work this folder for instance is c:\AB\RESOURCES. It contains things like pdf files which i can open via a menu from the forms and then will contain flat files that i write via the textbox on one of my forms, and then later another form can read this same file.


    is there anyway that i can write this directory automatically in c#

    any help appreciated

    tks

    neonitrix


Comments

  • Registered Users Posts: 7,504 ✭✭✭Trampas


    Sorry what do you mean write this directory?

    Create the directory?


  • Registered Users Posts: 620 ✭✭✭neonitrix


    yes sorry - I mean create a directory the first time the program runs so i can write files to it. at the moment i have hardcoded a location that is being read if the file dosnt exist a catch is outputting an error.

    tks

    neonitrix


  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh




  • Registered Users Posts: 1,017 ✭✭✭The_Thing


    Hi, I think this might do what you want - MainForm is the name of my form.
    private void MainForm_Shown(object sender, EventArgs e)
    {

    CenterToScreen();

    CheckForBaseFolder();

    }
    private void CheckForBaseFolder()
    {

    if (Directory.Exists(Configuration.BaseFolder))
    {



    }
    else
    {

    Directory.CreateDirectory(Configuration.BaseFolder);

    }

    }

    Configuration is a static class which I use to store all my 'magic numbers', strings, etc, as it helps to keep other classes free of clutter.
    class Configuration
    {

    //The name of our auto-generated 'Base' folder - change this string to suit your needs.
    private static string basefolder = @UserGeneratedContent;

    public static string BaseFolder
    {

    get { return basefolder; }

    }

    }


Advertisement