简体   繁体   中英

C# using Windows File Explorer to set selected file to string array?

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM