下面是以前一个功能的实现代码,现在因为要整合进MVC里面,所以想使用MVC改写一下,发现知识有些匮乏,实在不知道在MVC里面应该怎么读取二进制流,然后在视图中展示。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim QstrOffSet As String = Request.QueryString("offs")
If Not String.IsNullOrEmpty(QstrOffSet) Then
Dim FileName As String = Server.MapPath("App_Data\img.dat")
Dim openDataStream As New FileStream(FileName, FileMode.Open, FileAccess.Read)
Dim openDataBR As New BinaryReader(openDataStream)
Try
Dim OffSet As UInt32 = Convert.ToUInt32(QstrOffSet)
openDataStream.Seek(OffSet, SeekOrigin.Begin)
Dim Length As UInt32 = openDataBR.ReadUInt32()
If Length < 33000 Then
Response.ContentType = "application/x-MS-bmp"
Dim myByte() As Byte = openDataBR.ReadBytes(Length)
Response.BinaryWrite(myByte)
End If
Catch ex As Exception
Finally
openDataBR.Close()
openDataStream.Close()
openDataStream.Dispose()
End Try
End If
End If
End Sub
像
Response.ContentType = "application/x-MS-bmp"
Response.BinaryWrite(myByte)
这两段代码应该是关键问题所在,在MVC中我还不知道有什么API可以去处理这样的问题,希望能得到大家的帮助。
http://stackoverflow.com/questions/7163448/mvc-controller-using-response-stream