2012-08-24 141 views
3

我尝试上传文本文件到我的skydrive中,或者至少在SD中创建新的文本文件并通过我的Windows 8应用程序中的SkyDrive API编辑它的内容。 我该怎么做?通过SkyDrive API上传文件到skydrive API

我试图做这样的事情:

 LiveConnectClient client = new LiveConnectClient(session); 
     var fileData = new Dictionary<string, object>(); 
     fileData.Add("name", "new_file.txt"); 
     try 
     { 
      LiveOperationResult fileOperationResult = await client.PutAsync("me/skydrive", fileData); 
      this.infoTextBlock.Text = fileOperationResult.ToString(); 
     } 
     catch (LiveConnectException exception) 
     { 
      this.infoTextBlock.Text = exception.Message; 
     } 

,但我得到错误 “提供的请求是无效的根SkyDrive文件夹无法更新。” 如果我写的是“me/skydrive /”,我会得到 “提供的URL无效,请求的路径不受支持。 方法LiveConnectClient.PutAsync允许我只更新现有的属性(但不是它的内容)。

它应该如何正确完成?

顺便说一句 - 内容在LCDC(http://msdn.microsoft.com/en-us/library/live/hh826531.aspx)更新?我在问,因为文档中的某些方法在dll中不存在(f.e.LiveConnectClient.Upload。只有BackgroundUploadAsync)。

感谢提前的帮助, 迈克尔

回答

3

关闭,但正如我写道:我不能使用client.upload方法,因为LiveConnectClient类不包含它。这就是为什么我问网站内容更新的原因。

反正 - 我有一个答案:

//create a StorageFile (here is one way to do that if it is stored in your ApplicationData) 
StorageFile file = awaitApplicationData.Current.LocalFolder.GetFileAsync("yourfilename.txt"); 

try { 
    client = new LiveConnectClient(session); 
    LiveOperationResult operationResult = await client.BackgroundUploadAsync("me/skydrive", file.Name, file, OverwriteOption.Overwrite); 
} 
catch (LiveConnectException exception) { 
    //handle exception     
} 
2

您应该使用上LiveConnectionClient上传方法。例如,请参阅Live SDK中的Uploading Files example。就像...

LiveOperationResult fileOperationResult = 
    await client.Upload("me/skydrive", /*file name here*/, /*file stream here*/); 
0

这里的另一种方式上传使用从http://skydriveapiclient.codeplex.com/releases/view/103081

static void Main(string[] args) 
    { 
     var client = new SkyDriveServiceClient(); 

     client.LogOn("[email protected]", "password"); 
     WebFolderInfo wfInfo = new WebFolderInfo(); 

     WebFolderInfo[] wfInfoArray = client.ListRootWebFolders(); 

     wfInfo = wfInfoArray[0]; 
     client.Timeout = 1000000000; 

     string fn = @"test.txt"; 
     if (File.Exists(fn)) 
     { 
      client.UploadWebFile(fn, wfInfo); 
     } 

    } 
下载的SkyDriveApiClient一个控制台应用程序的文件