asp.net-mvc - 在asp.net MVC5中如何實作web form中的二進位流檔案輸出?
迷茫
迷茫 2017-05-16 17:06:09
0
1
269

下面是以前一個功能的實作程式碼,現在因為要整合進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可以去處理這樣的問題,希望能得到大家的幫助。

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!