-2

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.

  • Please share what you have tried!!!! – Abhishek Kumar Feb 08 '16 at 14:01
  • 1
    Try searching. [Select either a file or folder from the same dialog in .NET](http://stackoverflow.com/questions/428410/select-either-a-file-or-folder-from-the-same-dialog-in-net), [How can I get a folder or file path through a single WinForm dialog?](http://stackoverflow.com/questions/10391709/how-can-i-get-a-folder-or-file-path-through-a-single-winform-dialog), [How to use OpenFileDialog to select a folder? How to reuse .rc file from MFC in .NET project?](http://stackoverflow.com/questions/11624298/how-to-use-openfiledialog-to-select-a-folder-how-to-reuse-rc-file-from-mfc-in) – CodeCaster Feb 08 '16 at 14:19

2 Answers2

1

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.

René Vogt
  • 43,056
  • 14
  • 77
  • 99
  • Oh I like people downvoting answers without commenting. If there is something wrong with my answer, please let me know so I can do better next time. – René Vogt Feb 08 '16 at 15:24
  • It is because you've chosen to answer a question that 2 mins of Google searching would have found an answer to. The vote is now locked, or I would have reversed it based on this Meta answer: See: http://meta.stackoverflow.com/a/255861/1633308. But my sentiment remains: don't reward lazy question askers. And make use of `using` in your code. Lest you promote even more bad behavior. – DonBoitnott Feb 08 '16 at 15:43
  • @DonBoitnott I see your point and sometimes feel the same way. But sometimes it's easier to simply answer than to explain why not to answer...but I guess you're right, shouldn't have rewarded that question with an answer, especially since Andy Arndt already gave the right direction. – René Vogt Feb 08 '16 at 15:46
  • I used ddg and this was 2nd result and it helped. Thank you. – Vanity Slug - codidact.com Jun 22 '22 at 18:11
0

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.

https://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog(v=vs.110).aspx

Andy Arndt
  • 385
  • 1
  • 7