简体   繁体   中英

How to get the path to the skydrive folder in C#

I'm actually making a little application that can find on any computer the list of the different cloud storage installed and i wonder how i can get the path to the Skydrive folder in C#.

I managed to get the path of dropbox and google drive with information stored in appdata/roaming folder but i don't manage to do the same thing with Skydrive.

For dropbox:

string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string dbPath = System.IO.Path.Combine(appDataPath, "Dropbox\\host.db");                string[] lines = System.IO.File.ReadAllLines(dbPath);                
byte[] dbBase64Text = Convert.FromBase64String(lines[1]);
string folderPath = System.Text.ASCIIEncoding.ASCII.GetString(dbBase64Text);

For google drive :

String dbFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Google\\Drive\\sync_config.db");

            File.Copy(dbFilePath, "temp.db", true);
            String text = File.ReadAllText("temp.db", Encoding.ASCII);

            // The "29" refers to the end position of the keyword plus a few extra chars
            String trim = text.Substring(text.IndexOf("local_sync_root_pathvalue") + 29);

            // The "30" is the ASCII code for the record separator
            String drivePath = trim.Substring(0, trim.IndexOf(char.ConvertFromUtf32(30)));

If you want to get the path to the skydrive folder you need to use the Registery value at HKEY_CURRENT_USER\\Software\\Microsoft\\SkyDrive, with the name UserFolder. Here is the code :

String SkyDriveFolder = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\SkyDrive", "UserFolder",null).ToString();  

If you want to get the path to the skydrive folder you need to use the Registery value at HKEY_CURRENT_USER\\Software\\Microsoft\\SkyDrive, with the name UserFolder. Here is the code :

String SkyDriveFolder = Registry.GetValue("HKEY_CURRENT_USER\\Software\\Microsoft\\SkyDrive", "UserFolder",null).ToString();  

If you look in:

C:\Users\{username}\AppData\Local\Microsoft\SkyDrive\settings

you will see an .ini file, something like:

072d8533c42d12c1.ini - which contains:

library = 1 4 072d8533c42d12c1!173 121684168 "SkyDrive" Me personal "{path to skydrive folder}"

I'm not sure if this is a fool-proof way of finding the folders, use at your own risk!

It seems that in Windows 7 when you install the SkyDrive program, the SkyDrive path can be found in

HKEY_CURRENT_USER\Software\Microsoft\SkyDrive

However, in Windows 8 SkyDrive is part of the operating system and so the path is stored in

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\SkyDrive

To be more cross-platform compatible, just check both registry keys.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM