0

I'm starting a new project, and I need to be able to save/load users data.

I want them to click a button, then this brings up a file explorer where they select their .txt file. This .txt file then needs to be stored in a string array, where I can then manipulate the data.

If someone could point me in the right direction of what tools to use, that would be great. I've looked at OpenFileDialog, but I don't see how to assign it to an array.

Oli Smart
  • 67
  • 1
  • 1
  • 7
  • Do you want a tutorial for working with the txt file? writing and reading data from it? – Dave Mar 05 '15 at 12:58
  • If there's one already going that'd be good, if not don't worry. – Oli Smart Mar 05 '15 at 13:11
  • Have a look at some of these sections they should be helpful going forward https://msdn.microsoft.com/en-us/library/2kzb96fk.aspx – Dave Mar 05 '15 at 13:16

1 Answers1

2

Sounds like you're just looking for File.ReadAllLines - once you've got the filename, of courses. You need to separate out the tasks of "let the user select a file" from "read the contents of the file".

OpenFileDialog is probably the right tool to use for the first part, then File.ReadAllLines for the second...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Ahh yes I have used File.ReadAllLines before, but what I don't know is how to use the File explorer to set the path to a variable? – Oli Smart Mar 05 '15 at 12:54
  • @OliSmart: Well, you've looked at `OpenFileDialog` - did you not see anything in the documentation and the example that might tell you which file the user selected? – Jon Skeet Mar 05 '15 at 12:55
  • @OliSmart Take a look to get file path http://stackoverflow.com/questions/24449988/how-to-get-file-path-from-openfiledialog-and-folderbrowserdialog – Jamaxack Mar 05 '15 at 12:56