I have a C# WPF application and I am trying to find a way to get the path to the root OneDrive directory in Windows. How can I do this programmatically? I have searched online, but I couldn't find anything. I wish I could supply some code but I have no clue; I mean, I have checked system environment variables and I couldn't find anything on my machine, thinking that could be a valid solution, but it didn't turn up anything.
On my Windows 8.1 computer, the registry key that holds this information is: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\SkyDrive\UserFolder
I'd try using the Registry.GetValue()
method:
const string userRoot = "HKEY_CURRENT_USER";
const string subkey = @"Software\Microsoft\Windows\CurrentVersion\SkyDrive";
const string keyName = userRoot + "\\" + subkey;
string oneDrivePath = (string)Registry.GetValue(keyName,
"UserFolder",
"Return this default if NoSuchName does not exist.");
Console.WriteLine("\r\n OneDrivePath : {0}", oneDrivePath);
I also found the path under:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\SyncRootManager\SkyDrive\UserSyncRoots\S-1-5-21-2696997101-1021499815-432504798-1004
HKEY_USERS\S-1-5-21-2696997101-1021499815-432504798-1004\Software\Microsoft\Windows\CurrentVersion\SkyDrive\UserFolder