如何以编程方式使用C#找到我的Dropbox文件夹? [英] How do I programmatically locate my Dropbox folder using C#?

查看:139
本文介绍了如何以编程方式使用C#找到我的Dropbox文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用C#编程方式找到我的Dropbox文件夹?
*登记?
*环境变量?
*等等...

How do I programmatically locate my Dropbox folder using C#? * Registry? * Environment Variable? * Etc...

推荐答案

更新的解决方案

现在的Dropbox作为提供这里所说的info.json文件: HTTPS://www.dropbox。 COM / EN /帮助/ 4584

Dropbox now provides an info.json file as stated here: https://www.dropbox.com/en/help/4584

如果你不想处理解析JSON,你可以简单地用以下解决方案:

If you don't want to deal with parsing the JSON, you can simply use the following solution:

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如下:

If you'd like to parse the JSON, you can use the JavaScripSerializer as follows:

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"];

DE preCATED SOLUTION:

您可以阅读保管箱\\ host.db文件。这是位于你的应用程序数据\\漫游路径一个Base64文件。使用此:

You can read the the dropbox\host.db file. It's a Base64 file located in your AppData\Roaming path. Use this:

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);

希望它帮助!

这篇关于如何以编程方式使用C#找到我的Dropbox文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆