Search code examples
.netwpfonedrive

How can I reliably find the OneDrive directory path, so that I can allow user to write file to it


This seems like it should be so simple. Currently, I am "finding" this by iterating through the Quick Access entries for one marked "OneDrive" and getting the path. Looks like another way is to get the environment variable "OneDrive".

I have a little editor, and I'd like the user to be able to save the file "to the cloud". It occurred to me that an easy way to do this is to just save it to the OneDrive folder, and let the sync thing do it's thing.

Am I missing something obvious?


Solution

  • Environment.GetEnvironmentVariable("OneDriveConsumer") or Environment.GetEnvironmentVariable("OneDriveCommercial") should give a reliable path depending on whether you have one or several OneDrive clients on your machine.