gpt4 book ai didi

c# - AjaxFileUpload获取文件流

转载 作者:太空宇宙 更新时间:2023-11-03 18:11:50 25 4
gpt4 key购买 nike

我想用AjaxFileUpload这样获得文件System.IO.Stream。这是经典的FileUpload组件。

System.IO.Stream theStream = fileUpload.PostedFile.InputStream;


有人可以告诉我该怎么做吗?

最佳答案

您可以临时保存文件,然后阅读以获取FileStream。可能有点脏,但是对我有用。

VB.NET:

Dim tempPath As String = System.IO.Path.GetTempFileName()
yourAjaxFileUpload.SaveAs(tempPath)
Using fs As FileStream = File.OpenRead(tempPath)
'Do stuff with fs here
End Using
File.Delete(tempPath)


C#:

string tempPath = System.IO.Path.GetTempFileName();
yourAjaxFileUpload.SaveAs(tempPath);
using (FileStream fs = File.OpenRead(tempPath)) {
//do stuff with fs here
}
File.Delete(tempPath);

关于c# - AjaxFileUpload获取文件流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13392889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com