force download asp.net

Hi!

What's wrong??? Download doesn't work!

Many tks

            var arquivo = new FileInfo(Server.MapPath(@"~/plantas/arquivos/" + e.CommandArgument));

            Response.Clear();
            Response.ContentType = "application/acad";
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + e.CommandArgument);
            //Response.TransmitFile(arquivo.FullName);
            Response.WriteFile(arquivo.FullName);
            Response.End();
jbalessandroAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RickCommented:
You need to create a different HTTP Handler... can't modify the response of a page that has already been loaded ;)

Veja a resposta aqui. It's in C#, but can easily be translated into VB.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alrosmarzCommented:
you need a byte array this is for a pdf but u can use it for acad type

Response.Clear()
                Response.ContentType = "application/pdf"
                Response.AddHeader("Accept-Header", bytearray.lenght)
                Response.AddHeader("Content-Length", bytearray.lenght)
                Response.AppendHeader("Content-Disposition", "attachment; filename=name.pdf")
                Response.OutputStream.Write(byteArray, 0, bytearray.lenght)
                Response.Flush()

0
jbalessandroAuthor Commented:
so many tks

    public void ProcessRequest (HttpContext context) {
        var fileName = context.Request.QueryString["File"].ToString();
        var r = context.Response;
        r.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
        r.ContentType = "text/plain";
        r.WriteFile(context.Server.MapPath("/plantas/arquivos/" + fileName));
    }

works!!!!
0
jbalessandroAuthor Commented:
public void ProcessRequest (HttpContext context) {
        var fileName = context.Request.QueryString["File"].ToString();
        var r = context.Response;
        r.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
        r.ContentType = "text/plain";
        r.WriteFile(context.Server.MapPath("/plantas/arquivos/" + fileName));
    }

many tks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.