c# - Unable to make Save Dialog Save file -


So I'm trying to save a list of random numbers in a text file, the amount of random number (If they do number 2 input, then two random numbers are written in the file). I have received numbers in output in a text file in Visual Studio's default bin directory, but when I allow the user to select the desired directory and file name and choose to save the file after selecting the save button I do not see the file inside the explorer

Here's what this is:

  Private Zero instrument filebutton_link (object sender, Ivane Aarjis e) {// streamers object Strymwayr Output; Outputfile = file. CreateText ("Random.txt"); // Announce my counter, random object, and create variables to store user input random rand = new random (); Int desired intent; Int.TryParse (numberOfEntriesTextbox.Text, out desired); Int counter = 1; // user input and until user inputs make up the number up to the counter counter (counter & lt; = desired entries) {outputFile.WriteLine (rand.Next (100)); Counter ++; } // Save the resulting file in a txt document if (saveRandomFileDialog.ShowDialog () == DialogResult.OK) {outputFile = File.CreateText (saveRandomFileDialog.FileName); } Other {message box. Show ("You suck"); } OutputFile.Close (); }  

You are opening a file:

  Outputfile = file CreateText ("Random.txt");  

You write the file, and then after that you write the file, then you then ask the user where they File to save I see a problem here :)

Change the above line with this one:

  outputFile = file. Create Text (saveRandomFileDialog.FileName); Edit:  

Actually, your code should look like this (I removed you to run, but if you want to insult your users For evicting) :)

  if (saveRandomFileDialog. ShowDialog ()! = DialogResult.OK) {return; } (StreamWriter is using outputFile = File.CreateText (saveRandomFileDialog.FileName)) {Random RAND = New Random (); Int desired intent; Int.TryParse (numberOfEntriesTextbox.Text, out desired); Int counter = 1; Whereas (counter & lt; = desired entries) {outputFile.WriteLine (rand.Next (100)); Counter ++; }}  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -