如何以编程方式找到使用C#的Dropbox文件夹? *注册表? *环境变量? *等...如何以编程方式找到使用C#的Dropbox文件夹?
回答
更新的解决方案
如说这里的Dropbox现在提供了一个info.json文件:https://www.dropbox.com/en/help/4584
如果你不想处理解析JSON,你可以简单地采用如下方案:
var infoPath = @"Dropbox\info.json";
var jsonPath = Path.Combine(Environment.GetEnvironmentVariable("LocalAppData"), infoPath);
if (!File.Exists(jsonPath)) jsonPath = Path.Combine(Environment.GetEnvironmentVariable("AppData"), infoPath);
if (!File.Exists(jsonPath)) throw new Exception("Dropbox could not be found!");
var dropboxPath = File.ReadAllText(jsonPath).Split('\"')[5].Replace(@"\\", @"\");
如果你想解析JSON,您可以使用JavaScripSerializer如下:
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var dictionary = (Dictionary < string, object>) serializer.DeserializeObject(File.ReadAllText(jsonPath));
var dropboxPath = (string) ((Dictionary < string, object>)dictionary["personal"])["path"];
DEPRECATED SOLUTION:
您可以阅读保管箱\ host.db文件。它是位于AppData \ Roaming路径中的Base64文件。使用这个:
var dbPath = System.IO.Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Dropbox\\host.db");
var dbBase64Text = Convert.FromBase64String(System.IO.File.ReadAllText(dbPath));
var folderPath = System.Text.ASCIIEncoding.ASCII.GetString(dbBase64Text);
希望它有帮助!
使用'System.Text.Encoding.UTF8.GetString(dbBase64Text)'。我有一个用户拥有路径'C:\ Users \Jörg\ Dropbox',如果使用ASCII,将无法正确读取。 – jimbojones 2013-12-11 16:25:00
任何人都使用此代码:如果您在路径之前得到垃圾数据,请查看下面的[ivanatpr答案](http://stackoverflow.com/a/10401659/348336)。 – Gildor 2015-05-26 04:35:21
此方法在更高版本的Dropbox中停止工作。我的答案显示了目前的做法。 – Derek 2016-06-19 00:57:53
它没有存储在注册表中(至少它不是纯文本)。我相信它存储在以下位置。
C:\用户\用户配置文件\应用程序数据\漫游\ Dropbox的
我会说,它驻留在host.db或unlink.db文件。
config.db是一个sqlite文件。另外两个是未知的(加密的)。 config.db仅包含模式版本的blob字段。
更新2016年7月:下面的代码将不再有效因改变而在Dropbox的客户端,SEE接受的答案上面UP-TO-DATE SOLUTION
雷纳尔多的答案基本上是正确的,但它提供了一些垃圾输出在路径之前,因为host.db文件中似乎有两行,在这种情况下,您只需要阅读第二行。以下内容将为您提供路径。
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);
Console.WriteLine(folderPath);
基于以前的答案清洁版本(使用VAR,添加存在检查,删除警告):
private static string GetDropBoxPath()
{
var appDataPath = Environment.GetFolderPath(
Environment.SpecialFolder.ApplicationData);
var dbPath = Path.Combine(appDataPath, "Dropbox\\host.db");
if (!File.Exists(dbPath))
return null;
var lines = File.ReadAllLines(dbPath);
var dbBase64Text = Convert.FromBase64String(lines[1]);
var folderPath = Encoding.UTF8.GetString(dbBase64Text);
return folderPath;
}
这似乎是从Dropbox的建议的解决方案:https://www.dropbox.com/help/4584?path=desktop_client_and_web_app
这应该是被接受的答案:) – 2015-07-15 09:34:51
是的。这应该是被接受的答案。 'host.db'文件不是由更新版本的Dropbox创建的。读取'hosts.db'的旧方法可能适用于您的机器,因为没有Dropbox更新困扰删除文件。 – 2015-12-18 14:45:01
的Dropbox已添加一个新的帮手,在%APPDATA%\Dropbox\info.json
或%LOCALAPPDATA%\Dropbox\info.json
有一个JSON文件。
有关更多信息,请参阅https://www.dropbox.com/help/4584。
应该已经放入示例代码来阅读本文,并且您可能会获得更多upvotes并被接受为答案。 – DermFrench 2015-09-28 13:02:45
public static string getDropBoxPath()
{
try
{
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var dbPath = Path.Combine(appDataPath, "Dropbox\\host.db");
if (!File.Exists(dbPath))
{
return null;
}
else
{
var lines = File.ReadAllLines(dbPath);
var dbBase64Text = Convert.FromBase64String(lines[1]);
var folderPath = Encoding.UTF8.GetString(dbBase64Text);
return folderPath;
}
}
catch (Exception ex)
{
throw ex;
}
}
host.db方法在更高版本的Dropbox中停止工作。
https://www.dropbox.com/en/help/4584给出了推荐的方法。
这里是我写的解析json和获取dropbox文件夹的c#代码。
// https://www.dropbox.com/en/help/4584 says info.json file is in one of two places
string filename = Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Dropbox\info.json");
if (!File.Exists(filename)) filename = Environment.ExpandEnvironmentVariables(@"%APPDATA%\Dropbox\info.json");
JavaScriptSerializer serializer = new JavaScriptSerializer();
// When deserializing a string without specifying a type you get a dictionary <string, object>
Dictionary<string, object> obj = serializer.DeserializeObject(File.ReadAllText(filename)) as Dictionary<string, object>;
obj = obj[ "personal" ] as Dictionary<string, object>;
string path = obj[ "path" ] as string;
return path;
- 1. 如何以编程方式使用c#获得Dropbox共享文件夹的成员?
- 2. 以编程方式在c#中查找windows文件夹#
- 3. 如何以编程方式恢复Dropbox中的文件
- 4. 如何以编程方式查找ASP.NET App_Data文件夹路径
- 5. 如何使用C/C++以编程方式检查Windows系统文件夹?
- 6. 如何以编程方式在Dropbox中共享照片,文件夹等? (iOS)
- 7. C#:如何以编程方式获取Dropbox文件夹和文件的共享链接
- 8. 如何以编程方式使用Roslyn编译C#文件?
- 9. 你如何以编程方式找到Vista的“Saved Games”文件夹?
- 10. 如何以编程方式引用所需的值文件夹?
- 11. 以编程方式共享文件夹
- 12. 如何以编程方式更新VSTS文件(使用c#)
- 13. 如何以编程方式检入本地文件夹中的文件到TFS?
- 14. 如何以编程方式查找文件的编码?
- 15. 如何以编程方式查找使用C#的Google云端硬盘文件夹?
- 16. 如何以编程方式隐藏文件夹中的Android
- 17. 如何以编程方式查找可执行文件引用
- 18. Alfresco以编程方式导航到正确的文件夹
- 19. 如何以编程方式在Linux中查找文件格式?
- 20. 如何以编程方式访问ipad“Video”文件夹
- 21. 如何在cloudme中以编程方式复制文件夹
- 22. 如何在android中以编程方式打开文件夹?
- 23. 如何以编程方式锁定Android文件夹?
- 24. 如何在.Net中以编程方式解锁文件夹?
- 25. 如何在android中以编程方式隐藏文件夹
- 26. 如何在android中以编程方式锁定文件夹?
- 27. 如何以编程方式在Eclipse中设置源文件夹?
- 28. 如何以编程方式在Sharepoint站点创建文件夹
- 29. 如何以编程方式更改Wordpress上传文件夹?
- 30. 如何以编程方式查找php.ini文件的位置?
对不起 - 我的评论是无稽之谈,没有注意到,regkeys指向的Dropbox DLL,而不是保管箱的位置。发现这个论坛帖子,但看起来像它可能无法正常工作:http://forums.dropbox.com/topic.php?id=47895我个人做与DankDank相同,但会猜测这不会对用户个人如果他们更改默认位置,则进行安装。 – 2012-03-12 00:38:44
您是否在安装过程中尝试使用[Process Explorer](http://technet.microsoft.com/zh-cn/sysinternals/bb896653)以查看它的作用以及您可以找到哪些提示来检测它? – 2012-03-12 00:39:16