asp.net-mvc - How to implement binary stream file output in web form in asp.net MVC5?
迷茫
迷茫 2017-05-16 17:06:09
0
1
385

The following is the implementation code of a previous function. Now because it needs to be integrated into MVC, I want to rewrite it using MVC. I found that the knowledge is a bit lacking. I really don’t know how to read the binary stream in MVC and then display it in the view. .

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

picture

Response.ContentType = "application/x-MS-bmp"
 Response.BinaryWrite(myByte)

These two pieces of code should be the key problem. I don’t know what API can handle such problems in MVC. I hope you can help me.

迷茫
迷茫

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

reply all(1)
伊谢尔伦

http://stackoverflow.com/questions/7163448/mvc-controller-using-response-stream

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template