有什么方法可以检查“me / SkyDrive”位置的用户SkyDrive帐户中是否存在文件夹?
基本上我只是想知道如何做到这一点,因为我的应用程序具有skydrive功能,如果用户想要“me / Skydrive”中的文件夹,用户可以上传文件。但是每次用户登录SkyDrive帐户时我都添加了创建文件夹。这导致上传功能因为每个团队创建一个文件夹而中断,它会生成一个新的文件夹ID,在上传时会出错。
但重点是有没有办法检查SkyDrive目录中是否存在具有确切名称的文件夹?如果是这样的话?
这是我的代码,它基本上只是记录用户并创建一个文件夹:
private async void btnSignin_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
{
IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication();
if (e.Status == LiveConnectSessionStatus.Connected)
{
session = e.Session;
client = new LiveConnectClient(session);
StatusforSKD.Text = "You have signed in.";
try
{
var folderData = new Dictionary<string, object>();
folderData.Add("name", "File List");
LiveConnectClient liveClient = new LiveConnectClient(this.session);
LiveOperationResult operationResult = await liveClient.PostAsync("me/skydrive", folderData);
dynamic result = operationResult.Result;
InfoDD.Text = result.id;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "", MessageBoxButton.OK);
}
}
else
{
StatusforSKD.Text = "Not signed in.";
client = null;
}
}
答案 0 :(得分:1)
我不确定这个
答案 1 :(得分:1)
当您发现异常时,您可以执行以下操作:
if (exception.Message.Contains("already exists")
{
// ignore error and carry one because the folder already exists
}
答案 2 :(得分:0)
private async Task GetSkyDriveFolder()
{
if (liveClient == null)
await SignIn();
//the session is already established, so let's find our folder by its name
LiveOperationResult result = await liveClient.GetAsync("me/skydrive/files/");
List<object> data = (List<object>)result.Result["data"];
foreach (IDictionary<string, object> content in data)
{
if (content["name"].ToString() == folderName)
{
//The folder has been found!
folderID = content["id"].ToString();
MessageBox.Show("Folder exists hurray");
}
}
}
这将检查skydrive中是否存在文件夹