Download file directly to memory

前端 未结 3 1512
你的背包
你的背包 2020-12-14 17:35

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) me

3条回答
  •  不思量自难忘°
    2020-12-14 17:59

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

    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);
    }
    

    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);
    }
    

提交回复
热议问题