Skip to main content
 首页 » 编程设计

c#之在 OneDrive 上创建文本文件以设置和获取数据

2024年02月05日11dyllove98

是否有任何代码片段可以帮助我完成该任务?

  • OneDrive 身份验证
  • 在文本文件中保存一些变量,将该文件上传到 OneDrive。
  • 从 OneDrive 获取变量(如果存在)。

我在通用 Windows 10 应用程序上工作,希望用户将他们的设置保存在 OneDrive 上,以便稍后从任何其他设备获取它们。

感谢所有帮助

请您参考如下方法:

// Create a simple text file at onedrive:\Apps\<your UWP name>\Some Folder\Some File.txt 
 
// GetUniversalClient won't work until you associate your app with the store 
var onedrive = OneDriveClientExtensions.GetUniversalClient(new[] { "wl.signin", "onedrive.appfolder" }); 
await onedrive.AuthenticateAsync(); 
 
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello onedrive"))) 
{ 
    await onedrive.Drive.Special.AppRoot 
        .ItemWithPath("Some Folder/Some File.txt").Content 
        .Request().PutAsync<Item>(stream); 
}