为什么没有文件下载? [英] Why is the file not downloading?

查看:346
本文介绍了为什么没有文件下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着链接下载文件是在文件系统中。除了我用它Ext.net链接按钮,并在该按钮的Click事件做我加了相同的下载的代码。

I followed this link to download file that are in the file system. Except I did it using Ext.net link button, and in the click event of that button I added the same Download code.

设计部分是:

<ext:LinkButton ID="lnkDownload" Text="Download" runat="server">
        <DirectEvents>
            <Click OnEvent="lnkDownload_Click">
                <EventMask ShowMask="true" />
            </Click>
        </DirectEvents>
    </ext:LinkButton>

和代码隐藏的是:

protected void lnkDownload_Click(object s, DirectEventArgs e)
    { 
        string filePath = // Path to the file
        FileInfo file = new FileInfo(filePath);

        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AddHeader("Content-Length", file.Length.ToString());
            if (file.Extension == ".txt")
                Response.ContentType = "application/txt";
            else if (file.Extension == ".jpg")
                Response.ContentType = "image/jpg";
            else
                Response.ContentType = "application/octet-stream";
            Context.Response.WriteFile(file.FullName);
            Response.End();
        }
        else
        {
            Response.Write("This file does not exist.");
        }
    }

在运行的代码,就会发生错误。文本内容将显示文本文件,也许加密图像内容显示图像文件。发生什么事?为什么没有文件下载?请帮助我如何解决

When running the code, error occurs. Text content is displayed for text file, and maybe the encrypted image content is displayed for image file. What is happening? Why is the file not downloading? Please help me how to solve.

的快照:

推荐答案

有关它的工作代码更改为以下内容:

For it to work change the code to the following:

<ext:LinkButton ID="lnkDownload" Text="Download" runat="server">
        <DirectEvents>
            <Click OnEvent="lnkDownload_Click" IsUpload="true">
                <EventMask ShowMask="true" />
            </Click>
        </DirectEvents>
</ext:LinkButton>

注意:我觉得内容类型应该永远是应用程序/八位字节-stream。

Note: I think the content type should always be "application/octet-stream".

修改

有关面具,按<一个HREF =http://forums.ext.net/showthread.php?27575-Download-File-using-DirectEvent相对=nofollow>丹尼尔从Ext.NET小组,的它不可能没有一个解决办法

代码

<ext:LinkButton ID="lnkDownload" Text="Download" runat="server">
        <DirectEvents>
            <Click OnEvent="lnkDownload_Click" Success="Ext.net.DirectMethods.Download({ isUpload : true });" IsUpload="true">
                <EventMask ShowMask="true" />
            </Click>
        </DirectEvents>
</ext:LinkButton>

这篇关于为什么没有文件下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆