C# 上载到skydrive的特定文件夹
我想上传一个.txt列表,并将它们保存在skydrive上的自定义文件夹中 像某人的帐户->Skydrive->自定义文件夹('testfile')) 我试过了C# 上载到skydrive的特定文件夹,c#,windows-phone-8,onedrive,C#,Windows Phone 8,Onedrive,我想上传一个.txt列表,并将它们保存在skydrive上的自定义文件夹中 像某人的帐户->Skydrive->自定义文件夹('testfile')) 我试过了 LiveOperationResult res=wait client.BackgroundUploadAsync(“me/skydrive/testfile”,新Uri(“/shared/transfers/”+t,UriKind.Relative),OverwriteOption.Overwrite), 但它根本不起作用,它给了我一
LiveOperationResult res=wait client.BackgroundUploadAsync(“me/skydrive/testfile”,新Uri(“/shared/transfers/”+t,UriKind.Relative),OverwriteOption.Overwrite)代码>,
但它根本不起作用,它给了我一个错误:
URL包含不受支持的路径“testfile”
如果我需要获取文件夹ID才能上载文件,如何获取ID
这是我的密码:
private async void button_Click(object sender, EventArgs e)
{
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
var temptempout = new List<String>(isoStore.GetFileNames("*").ToList());
int total = temptempout.Count;
int now = 0;
if (temptempout.Count > 0)
{
ShowTextDebug.Text = "Uploaded 0 of " + total + " files";
foreach (String t in temptempout)
{
using (var fileStream = isoStore.OpenFile(t, FileMode.Open, FileAccess.Read))
{
try
{
LiveOperationResult res = await client.BackgroundUploadAsync("me/skydrive/testfile",
new Uri("/shared/transfers/" + t, UriKind.Relative),
OverwriteOption.Overwrite
);
}
catch (Exception err)
{
String rrtt = "there is an error while uploading txt " + err.Message;
MessageBox.Show(rrtt, "error", MessageBoxButton.OK);
}
}
now++;
ShowTextDebug.Text = "Uploaded " + now + " of " + total + " files";
}
ShowTextDebug.Text += "\nupload complete";
}
else
{
MessageBox.Show("no txt exist", "error", MessageBoxButton.OK);
}
}
private async void按钮\u单击(对象发送方,事件参数e)
{
IsolatedStorageFile isoStore=IsolatedStorageFile.GetUserStoreForApplication();
var testempout=新列表(isoStore.GetFileNames(“*”).ToList();
int total=TENTEMPOUT.Count;
现在int=0;
如果(testempout.Count>0)
{
ShowTextDebug.Text=“上载了0个”+总计+“文件”;
foreach(TENTEMPOUT中的字符串t)
{
使用(var fileStream=isoStore.OpenFile(t,FileMode.Open,FileAccess.Read))
{
尝试
{
LiveOperationResult res=await client.BackgroundUploadAsync(“me/skydrive/testfile”,
新Uri(“/shared/transfers/”+t,UriKind.Relative),
覆盖选项。覆盖
);
}
捕获(异常错误)
{
String rrtt=“上传txt时出错”+错误消息;
MessageBox.Show(rrtt,“error”,MessageBoxButton.OK);
}
}
现在++;
ShowTextDebug.Text=“上传”+now+”共“+total+”个文件;
}
ShowTextDebug.Text+=“\n加载完成”;
}
其他的
{
MessageBox.Show(“不存在文本”,“错误”,MessageBoxButton.OK);
}
}
感谢您的帮助您需要先获取文件夹id。您可以按如下方式进行操作:
private async Task<string> GetSkyDriveFolderID(string folderName)
{
client = App.LiveClient;
LiveOperationResult operationResult = await client.GetAsync("me/skydrive/files?filter=folders");
var iEnum = operationResult.Result.Values.GetEnumerator();
iEnum.MoveNext();
var folders = iEnum.Current as IEnumerable;
foreach (dynamic v in folders)
{
if (v.name == folderName)
{
return v.id as string;
}
}
return null;
}
您需要先获取文件夹id。您可以按如下方式进行操作:
private async Task<string> GetSkyDriveFolderID(string folderName)
{
client = App.LiveClient;
LiveOperationResult operationResult = await client.GetAsync("me/skydrive/files?filter=folders");
var iEnum = operationResult.Result.Values.GetEnumerator();
iEnum.MoveNext();
var folders = iEnum.Current as IEnumerable;
foreach (dynamic v in folders)
{
if (v.name == folderName)
{
return v.id as string;
}
}
return null;
}