[英]Windows 10 App - File downloading
我正在使用Windows 10通用应用程序,我想在其中下载文件。 指向Sharepoint服务器的文件链接。 我已将标头中的令牌传递给Web服务,然后服务将字节数组返回给WinJS。
现在我要保存文件,我该怎么做? 我尝试了几个代码示例,但是没有用。
var folder = Windows.Storage.ApplicationData.current.localFolder;
folder.createFileAsync("document.docx", Windows.Storage.CreationCollisionOption.replaceExisting).then(function (file) {
return Windows.Storage.FileIO.writeTextAsync(file, result.response);
}).then(function () {
//saved
});
我正在使用上面的代码,它正在创建新文件,但没有内容放置在那里。 请提出建议。
您永远不会为WriteAccess打开文件。 我已经包含了我正在运行的应用程序中的代码。 首先执行此命令
StorageFile ageFile = await local.CreateFileAsync("Age.txt", CreationCollisionOption.FailIfExists);
然后这样做:
// Get the file.
var ageFile = await local.OpenStreamForWriteAsync("Age.txt",CreationCollisionOption.OpenIfExists);
// Read the data.
using (StreamWriter streamWriter = new StreamWriter(ageFile))
{
streamWriter.WriteLine(cmbAgeGroup.SelectedIndex + ";" + DateTime.Now);
streamWriter.Flush();
}
ageFile.Dispose();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.