简体   繁体   English

c# uwp 从网络读取 csv

[英]c# uwp read csv from web

I am trying to make an app that make use of open data.我正在尝试制作一个利用开放数据的应用程序。 The data I try to read out is in a CSV format (and is about 40mb big).我尝试读出的数据是 CSV 格式(大约 40mb 大)。

I have 2 problems I can't solve.我有两个问题无法解决。

  • First I having difficulties to read the file from the web.首先,我很难从网上读取文件。 I already read on MSDN how to read files asynchrome but it's all about local files.我已经在 MSDN 上阅读了如何异步读取文件,但这都是关于本地文件的。 I want to make a list of objects.我想列出一个对象列表。 Each line (except the first line) contains all props for 1 object每行(第一行除外)包含 1 个对象的所有道具

  • Secondly when I finally managed to read the file, is there a way to save it's data and read it somehow the next time?其次,当我最终设法读取文件时,有没有办法保存它的数据并在下次以某种方式读取它? Because 40mb is pretty big to re-download each time you open the app and it takes a lot of time.因为每次打开应用程序时重新下载 40mb 是相当大的,而且需要很多时间。 I was wondering if it is possible that when I read the the file on the web again, it will only read and at the new lines.我想知道是否有可能当我再次阅读网络上的文件时,它只会读取 和 新行。

I am a newbie in UWP (c#) applications, so my apologies for the questions.我是 UWP (c#) 应用程序的新手,所以我对这些问题深表歉意。

Thanks in advance.提前致谢。

There are two APIs you can use to download a file.您可以使用两个 API 来下载文件。 One is HttpClient , described here on MSDN Documentation and in a UWP sample here .一个是HttpClient在此处的 MSDN 文档此处UWP 示例中进行了描述 This class is usually recommended for smaller files and smaller data, but can easily handler larger files as well.此类通常推荐用于较小的文件和较小的数据,但也可以轻松处理较大的文件。 Its disadvantage is, that when the user closes the app, the file will stop downloading.它的缺点是,当用户关闭应用程序时,文件将停止下载。

The alternative is BackgroundDownloader , again here on MSDN and here in UWP samples .另一种方法是BackgroundDownloader ,同样在 MSDNUWP 示例中 This class is usually recommended for downloading larger files and data, as it automatically perfroms the download in the background so the download will continue even when the app is closed.此类通常推荐用于下载较大的文件和数据,因为它会在后台自动执行下载,因此即使应用程序关闭,下载也会继续。

To store your files, you can use the ApplicationData.Current.LocalFolder .要存储文件,您可以使用ApplicationData.Current.LocalFolder This is a special folder provided to you by the system for storage of application files.这是系统提供给您的一个特殊文件夹,用于存储应用程序文件。 You have read/write access to this folder and you can not only store your files here, but even create subfolder structure using UWP StorageFile and StorageFolder APIs.您对此文件夹具有读/写访问权限,不仅可以在此处存储文件,还可以使用 UWP StorageFileStorageFolder API 创建子文件夹结构。 More about this is on MSDN .更多关于这方面的信息在 MSDN 上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM