BROWSING THE CLOUD

Giorgio Sfiligoi 126 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.
10,096 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,109 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,571 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