使用memorystream将文件保存到设备 [英] Save file to device with memorystream

查看:198
本文介绍了使用memorystream将文件保存到设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道xamarin.forms是否可以将任何类型的文件下载到设备上..de文件存储在Azure上,我得到了文件的Memorystream,这对于我的应用程序非常重要.我的问题实际上分为两部分, 如何将文件下载到用户的设备?, 以及如何在该类型的默认应用程序(例如pdf阅读器)中显示Any类型的文件

I was wondering if it is possible with xamarin.forms to download any type of file to the device.. de files are stored on Azure, i get a Memorystream of the file, its very important for my app. my question excists of 2 parts actually, how to download de file to the device of the user?, and how to show the file of Any type in a default application of the type ( like pdf reader)

这就是我尝试过的

MemoryStream memoryStream = AzureDownloader.DownloadFromAzureBlobStorage(null,doc.azure_container,doc.file_path,ref filen,true);

MemoryStream memoryStream = AzureDownloader.DownloadFromAzureBlobStorage(null, doc.azure_container, doc.file_path, ref filen, true);

  string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
  string localFilename = doc.filename;
  string localPath = Path.Combine(documentsPath, localFilename);
  File.WriteAllBytes(localPath, memoryStream.ToArray()); // this is a try to save to local storage

任何帮助表示赞赏

推荐答案

如何将文件下载到用户的设备上?

how to download the file to the device of the user?

使用 PCLStorage 作为其跨平台,并适用于iOS和Android:

Use PCLStorage as its cross-platform and would work for iOS and Android:

public async Task CreateRealFileAsync()
{
    // get hold of the file system
    IFolder rootFolder = FileSystem.Current.LocalStorage;

    // create a folder, if one does not exist already
    IFolder folder = await rootFolder.CreateFolderAsync("MySubFolder", CreationCollisionOption.OpenIfExists);

    // create a file, overwriting any existing file
    IFile file = await folder.CreateFileAsync("MyFile.txt", CreationCollisionOption.ReplaceExisting);

    // populate the file with some text
    await file.WriteAllTextAsync("Sample Text...");
}

如何在该类型的默认应用程序中显示任何类型的文件 (如pdf阅读器)

how to show the file of Any type in a default application of the type ( like pdf reader)

这太广泛了,可能有几种解决方案,具体取决于您要实现的目标.

this is too broad and could have several solutions depending on what exactly you want to achieve.

希望这会有所帮助

这篇关于使用memorystream将文件保存到设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆