How to select a place to create a folder in windows form c#?
I'm doing my computing coursework and I'm creating program where your school files will be synchronized to a selected folder at home(similarly to Dropbox). When you login I need it to ask you the user to select a place and create folder where the files will be synchronized to but I'm not sure how to do it.
I would really appreciate if anyone could provide some examples.
I'll point you to the documentation, that includes examples. You could have easily found this by Googling, though. And if you're doing coursework that involves programming, first lesson is to learn to find things on Google.
The .NET Framework and Windows.Forms provides you a solution for this. You can simply use a FolderBrowserDialog like this:
using (FolderBrowserDialog dialog = new FolderBrowserDialog())
dialog.Description = "Select path to synchronize to";
dialog.RootFolder = Environment.SpecialFolder.Desktop; // or whatever you like
dialog.SelectedPath = ...; // maybe set this to a previously selected folder
dialog.ShowNewFolderButton = true; // to enable the user to create a new folder
if (dialog.ShowDialog() != DialogResult.OK) return; // do what you need if user cancels the dialog
var selectedPathToSynchronizeTo = dialog.SelectedPath;
This shows the Windows standard folder selection dialog.
Asked in February 2016Viewed 3,354 timesVoted 6Answered 2 times