2

In my Form1 Event, not everything is completed. Only the first line is actually executed.

private void Form1_Load(object sender, EventArgs e)
    {
        //Save the currentUser text document's contents into the currentUser string
        System.IO.StreamReader file = new System.IO.StreamReader("C\\Users\\WoopyCat\\AppData\\Roaming\\.minecraft\\currentUser.txt");
        currentUser = file.ReadLine();

        //Save the currentUser into the textbox
        TBcurrentUser.Text = "The current user is " + currentUser + ".";

        //Set the default text for the textbox
        TBchangeTo.Text = "Whose Minecraft folder are you switching to?";

        //Add the default two items to the listbox
        LBfiles.Items.Add("Minecraft folders:" + Environment.NewLine);
        LBfiles.Items.Add("---------------------------------------------------------------------------------------------------------------------------");

        //Create the directory if it doesn't exist
        if (!Directory.Exists("C:\\Users\\WoopyCat\\AppData\\Roaming\\" + folderName))
        {
            Directory.CreateDirectory("C:\\Users\\WoopyCat\\AppData\\Roaming\\" + folderName);
        }

        //Set the default instructions in the textbox
        TBinstructions.Text = instructions;

        //Add each directory to the listbox
        foreach (string value in Directory.GetDirectories("C:\\Users\\WoopyCat\\AppData\\Roaming\\" + folderName))
        {
            //Remove the file location from the string
            each = value.Replace("C:\\Users\\WoopyCat\\AppData\\Roaming\\.MCSwitcher\\", "");
            LBfiles.Items.Add(each + Environment.NewLine);
        }
    }

Nothing happens when the form loads. If I add a first line, then it actually occurs. Like if I call a messagebox as the first line in this event, it happens. But nothing in this code does.

TheUnrealMegashark
  • 309
  • 1
  • 6
  • 19
  • 1
    Have you tried putting your code in the constructor, instead, right after `InitializeComponent();`? – tinstaafl Jul 14 '13 at 07:23
  • 2
    Your code ran into exception and .Net just swallowed the exception so it looks like it stopped running in the middle of the method. See http://stackoverflow.com/questions/3209706/why-the-form-load-cant-catch-exception – tia Jul 14 '13 at 07:28

1 Answers1

2

change

System.IO.StreamReader file = new System.IO.StreamReader("C\\Users\\WoopyCat\\AppData\\Roaming\\.minecraft\\currentUser.txt");

to

System.IO.StreamReader file = new System.IO.StreamReader("C:\\Users\\WoopyCat\\AppData\\Roaming\\.minecraft\\currentUser.txt");

You forgot the colon

prospector
  • 3,389
  • 1
  • 23
  • 40