代码适用于IE8,但不适用于IE10

时间:2015-08-06 23:23:43

标签: asp.net vb.net

我的网页上有以下代码:

Protected Function SendData(ByVal filepath As String) As Boolean

        Dim ReturnResults As Boolean = False
        Dim iStream As System.IO.Stream = Nothing

        Dim buffer As Byte() = New [Byte](9999) {}
        Dim length As Integer
        Dim dataToRead As Long
        Dim filename As String = System.IO.Path.GetFileName(filepath)
        Try
            iStream = New System.IO.FileStream(filepath, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
            dataToRead = iStream.Length
            Response.Clear()
            Response.ContentType = "application/octet-stream"
            Response.AddHeader("Content-Disposition", "attachment; filename=" & filename)
            While dataToRead > 0
                If Response.IsClientConnected Then
                    length = iStream.Read(buffer, 0, 10000)
                    Response.OutputStream.Write(buffer, 0, length)
                    Response.Flush()
                    buffer = New [Byte](9999) {}
                    dataToRead = dataToRead - length
                Else
                    dataToRead = -1
                End If
            End While
            Response.Close()
            ReturnResults = True
        Catch ex As Exception
            Response.Write(ex.Message)
        Finally
            If iStream IsNot Nothing Then
                iStream.Close()
            End If
        End Try
        Return ReturnResults
    End Function

以上代码在IE8中运行良好,它允许我们在IE8中打开并保存文件,但是当我在IE10中尝试相同的代码时,它会给我一个错误,说“文件无法打开”。我不确定它是IE问题还是其他什么,但我不知道如何更改上面的代码,以便它开始在IE10中工作。

我还将标记放在显示

的网页上方
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"/>' 

我也尝试过进行兼容模式。我还将上面的内容放在web.config文件中,以便它适用于整个应用程序,但似乎没有任何工作。我也试过

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>'

也不起作用。

非常感谢任何帮助。

0 个答案:

没有答案