English 中文(简体)
ASP. NET从链接中下载菜单
原标题:ASP.NET download menu from a link

我试图解决下列问题:

I have a download button that when clicked, redirects to a file for download. Example:

答复:Redirect(http://www.example.com/data/file1.zip);

当这个纽子被点击时,你就拿到了一张菜单,因为你可以要求科索沃下载。

但是,如果我有:

答复:Redirect(http://www.example.com/data/textfile.txt);

I get a piece of text instead. I don t want this behavior.

How can I make a menu pop all cases when you click to download the file.

我尝试如下:

Response.ContentType = "application/octet-stream";

Response.Redirect("http://www.example.com/data/" + filename);

但是,如果我点击它的话,我仍然只是拿着灯塔的内容。 是否有办法检查是否实际采用了这种奇米类型?

最佳回答

您需要确定反应类型,

流层应迫使用户开放或拯救档案

类似情况

public class Download : IHttpHandler {
    public void ProcessRequest (HttpContext context) {
        string filename = context.Request.QueryString["file"];
        string file = context.Server.MapPath(filename);
        context.Response.ContentType = "application/octet-stream";
        context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename));
        try
        {
            context.Response.TransmitFile(file);
        }
        catch (Exception ex)
        {
            SendFailedDownload(filename, context);
        }
        finally
        {
        }
    }
}
问题回答

不要采取上述行动,就只是使用链条,把手ef锁定在案卷中。 这不需要调整方向或调整情况。

<a href="<link to file>" title="">Download me </a>

这将促使你拯救或开放......

t 案卷的工作的确为其他文件工作。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签