不要将文件下载到内存

时间:2015-07-16 07:11:52

标签: vb.net stream

我正在进行从.doc和.docx到html的转换。 这现在如下工作:

Using wc As New Net.WebClient()
    Dim buffer = wc.DownloadData(fileurl)
    Dim stream = new MemoryStream(buffer)
    doc = New Document(stream) ' this is from the conversion library, accepts: fileurl and SysteM.IO.Stream
End Using

但是当使用较大的文件时,这些内容都会被加载到内存中。我最好不要这样做。

但我似乎无法找到如何读取流数据而不将其全部加载到memroy中。我尝试使用wc.OpenRead()但我得到了:"This stream does not support seek operations."

1 个答案:

答案 0 :(得分:2)

您可以尝试使用WebClient.DownloadFile()

E.g。

Dim filePath As String = "C:\file.doc"

Using wc As New Net.WebClient()
    wc.DownloadFile(fileurl, filePath)
    doc = New Document(filePath)
End Using