question

GiorgioSfiligoi-6452 avatar image
0 Votes"
GiorgioSfiligoi-6452 asked TimonYang-MSFT answered

BROWSING THE CLOUD

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.

dotnet-csharpdotnet-runtime
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

With IFileSaveDialog or IFileOpenDialog and FOS_PICKFOLDERS, I have OneDrive for example :

(edit : or a simple SaveFileDialog)

64825-onedrive.jpg





0 Votes 0 ·
onedrive.jpg (81.3 KiB)

1 Answer

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.