我想用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/