首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下载后文件损坏

下载后文件损坏
EN

Stack Overflow用户
提问于 2017-10-13 19:42:37
回答 1查看 546关注 0票数 0

在ASP.NET (VB.NET)中下载文件后打开文件时收到以下错误-远程服务器共享路径有文件。

以下代码用于下载文件:

代码语言:javascript
复制
Private Sub downloadFile(ByVal file As String)

    Try
        Dim requestFile As String = "\\ashleyfurniture\afi-dfs\Arcadia\Vaults\Web\AshleyDirectAttachments\IdeaNetwork\Images" + "\" + file

        If String.IsNullOrEmpty(requestFile) Then
            Throw New FileNotFoundException("File to download cannot be null or empty")
        End If

        ' Get file name from URI string in C#

        Dim uri = New Uri(requestFile)
        Dim filename As String = Path.GetFullPath(uri.OriginalString)
        Dim fileInfo = New FileInfo((uri.OriginalString))

        If Not fileInfo.Exists Then
            Throw New FileNotFoundException("File to download was not found", uri.OriginalString)
        End If


        Response.ContentType = "application/octet-stream"

        Response.AddHeader("Content-Disposition", "attachment; filename=""" + fileInfo.Name + """")
        Response.WriteFile(fileInfo.FullName)
        Response.End()



        ' ignore exception
    Catch generatedExceptionName As ThreadAbortException

    Catch ex As FileNotFoundException
        Response.StatusCode = CInt(System.Net.HttpStatusCode.NotFound)
        Response.StatusDescription = ex.Message
    Catch ex As Exception
        Response.StatusCode = CInt(System.Net.HttpStatusCode.InternalServerError)
        Response.StatusDescription = String.Format("Error downloading file: {0}", ex.Message)
    End Try



End Sub
EN

回答 1

Stack Overflow用户

发布于 2017-10-13 19:55:02

同意Wiktor Zychla的观点

尝试删除响应的ContentType

代码语言:javascript
复制
Response.ContentType = "application/octet-stream"
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46729153

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档