2016-05-15 111 views
0

我目前正在研究UWP XAML/C#應用程序,並且需要將數據存儲到本地文件夾。當執行下面的代碼時,我得到這個錯誤:'IAsyncAction'不包含'GetAwaiter'的定義,並且最好的擴展方法重載'AwaitExtensions.GetAwaiter(Task)'需要類型'Task'的接收器。在UWP應用程序中存儲文件時的問題

StorageFile file = await localFolder.CreateFileAsync("userInformation.txt", CreationCollisionOption.ReplaceExisting); 
await FileIO.WriteTextAsync(file, responseContent.ToString())); 

Screenshot

更新:完整的方法

private async void Login() 
    { 
     StorageFile file = await localFolder.CreateFileAsync("userInformation.txt", CreationCollisionOption.ReplaceExisting); 
     await FileIO.WriteTextAsync(file, "sample txt"); 
    } 
+0

我測試了你的代碼,它在我身邊正常工作,你是如何得到本地文件夾的?你能否請創建一個新的空UWP項目並再次測試這個代碼? –

+0

當這樣做時,我得到錯誤:類型'IAsyncOperation'是在未引用的程序集中定義的。 –

+0

如果創建一個新的空項目並不能解決這個問題,那麼我認爲問題可能出在你的VS工具上,請嘗試重新安裝VS. –

回答

0

此代碼的工作沒有任何問題:

StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync("userInformation.txt", CreationCollisionOption.ReplaceExisting); 
await FileIO.WriteTextAsync(file, "some text"); 

當我看到有在你的代碼一個額外的支架。第二行應該是:

await FileIO.WriteTextAsync(file, responseContent.ToString()); 
+0

我不知道,有什麼問題......但對我來說,這將不起作用 –

+0

您是否嘗試用一些文本替換responseContent.ToString()。在第二行寫入等待FileIO.WriteTextAsync(文件,「一些文本」); –

+0

是的,我已經試過了。 –

相關問題