简体   繁体   English

如何自动从Web检索CSV文件,将其保存在目录中并在C#中访问它?

[英]How can I automatically retrieve a CSV file from web, save it in a directory, and access it in C#?

I am working on an application which has to retrieve data from a CSV file online and display it with a click of a button. 我正在开发一个应用程序,该应用程序必须在线从CSV文件中检索数据并单击一下按钮将其显示。 However, how can I automatically store the CSV file in a safe place where I can access the information? 但是,如何自动将CSV文件存储在可以访问信息的安全位置? I am working with Visual Studio C#. 我正在使用Visual Studio C#。

Thank you. 谢谢。

You want to use the WebClient class to make an http request to the server for the csv file. 您要使用WebClient类向服务器发出对csv文件的http请求。 It should read the whole contents as a string which you can then parse and manipulate at your leisure. 它应将整个内容读取为字符串,然后可以在闲暇时对其进行解析和操作。

http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.100).aspx http://msdn.microsoft.com/zh-cn/library/system.net.webclient(VS.100).aspx

Use System.IO.File to write the contents to a file. 使用System.IO.File将内容写入文件。

http://msdn.microsoft.com/en-us/library/system.io.file.aspx http://msdn.microsoft.com/en-us/library/system.io.file.aspx

The FileHelpers are a free and easy to use .NET library to import/export data from fixed length or delimited records in files, strings or streams. FileHelpers是一个免费且易于使用的.NET库,用于从文件,字符串或流中的固定长度或定界记录中导入/导出数据。

The FileHelpers Library FileHelpers库
http://www.filehelpers.com/ http://www.filehelpers.com/

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

相关问题 如何将csv文件的不同行(数值值)读取(保存)到C#中的不同数组中 - How can I read (save) different lines (of numeric values) of a csv file into different arrays in C# 如何从C#将文件发布到Web API? - How i can post file to web API from C#? 我如何 zip XMLDocuments 的集合并将其保存到 C# 中的目录 - How can I zip a collection of XMLDocuments and save it to a directory in C# 我通过下面的脚本获取xml文件,但是如何在C#页面上保存和访问? - I am getting the xml file by below script But how can I save and access on C# page? 如何仅从 C# 中的 web 服务的 URL 检索 SoapEnvelope 信息? - How can I retrieve SoapEnvelope information just from the URL of web services in C#? 如何在C#等待调用中使用Rx从Web检索JSON数据 - How can I use Rx with C# await calls to retrieve JSON data from web 如何从C#中的访问数据库中检索列描述? - How can I retrieve column descriptions from an access database in C#? 如何从 C# 访问基于 url 的目录 sharepoint? - How can I access a sharepoint url-based directory from C#? 如何从C#代码中将生成的值检索到web.config文件中? - How can I retrieve a generated value from my C#-code into my web.config file? 如何使用PowerShell和C#检索每个.bak文件? - How can I retrieve every .bak file with PowerShell and C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM