BROWSING THE CLOUD

Giorgio Sfiligoi 266 Reputation points
2021-02-06T16:55:04.647+00:00

My desktop application needs to save certain files in a folder selected by the user. FolderBrowserDialog can do the job, but only for local files; it does not 'see' network folders and the cloud.
I would like to allow the user select a folder e.g. in OneDrive, or DropBox, or what have you - provided of course he has an account.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,121 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,179 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,591 Reputation points
    2021-02-08T06:30:52.943+00:00

    The OpenFileDialog seems to be able to achieve your needs.

    var fileContent = string.Empty;  
    var filePath = string.Empty;  
      
    using (OpenFileDialog openFileDialog = new OpenFileDialog())  
    {  
        openFileDialog.InitialDirectory = "c:\\";  
        openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";  
        openFileDialog.FilterIndex = 2;  
        openFileDialog.RestoreDirectory = true;  
      
        if (openFileDialog.ShowDialog() == DialogResult.OK)  
        {  
            //Get the path of specified file  
            filePath = openFileDialog.FileName;  
      
            //Read the contents of the file into a stream  
            var fileStream = openFileDialog.OpenFile();  
      
            using (StreamReader reader = new StreamReader(fileStream))  
            {  
                fileContent = reader.ReadToEnd();  
            }  
        }  
    }  
      
    MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK);  
    

    Is there anything you need that it doesn't have?


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.