直接下载文件到内存 [英] Download file directly to memory

查看:163
本文介绍了直接下载文件到内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载一个Excel直接从ftp站点文件到内存流。然后我想打开使用OpenExcel(流)方法公司Farpoint传播控制的文件。我的问题是我不知道是否有可能直接下载文件到内存中。任何人都知道这是可能的?

I would like to load an excel file directly from an ftp site into a memory stream. Then I want to open the file in the FarPoint Spread control using the OpenExcel(Stream) method. My issue is I'm not sure if it's possible to download a file directly into memory. Anyone know if this is possible?

推荐答案

是的,你可以从FTP下载文件到内存中。

Yes, you can download a file from FTP to memory.

我想你甚至可以从FTP服务器通过公司Farpoint处理通流。

I think you can even pass the Stream from the FTP server to be processed by FarPoint.

        WebRequest request = FtpWebRequest.Create("ftp://asd.com/file");

        using (WebResponse response = request.GetResponse())
        {
            Stream responseStream = response.GetResponseStream();
            OpenExcel(responseStream);
        }



使用Web客户端,你可以做几乎相同。一般使用Web客户端更容易,但给你少配置选项和控制(如:无超时设置)。

Using WebClient you can do nearly the same. Generally using WebClient is easier but gives you less configuration options and control (eg.: No timeout setting).

        WebClient wc = new WebClient();
        using (MemoryStream stream = new MemoryStream(wc.DownloadData("ftp://asd.com/file")))
        {
            OpenExcel(stream);
        }

这篇关于直接下载文件到内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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