c# - ASP Force download txt file sending back source instead -


My ASP has a function that returns a TXT file.

I want the user to download the file, but the browser wanted to display it when I did Response.Redirect ("/ Dir / Dir / TextFilePath.txt") ;

So I've found that if you add it, it forces you to download it in the header.

  Response Adhider ("content-disposo", "attachment; filename = / dr / dar / textfilepath.Text");   

And this force downloads the file with a catch.

The file is ASPX source code and not my TCT file .... this is the correct name but it is definitely not a TCTIF file.

Here is a correct way to download files in ASP.NET 'a right way' and note Do not keep the 'right way', you can do it in other ways but it works for me.

  try {Response.Clear ()); Response.ClearHeaders (); Response.ClearContent (); Response.AddHeader ("content-effect", "attachment; file name =" + _philename); Response.AddHeader ("Content-Type", "App / Word"); Response.ContentType = "app / octet-stream"; Response.AddHeader ("content-length", _FileLength_in_bytes); Response.BinaryWrite (_Filedata_bytes); Response.End (); } Hold (ThreadAbortException) {} Finally {}   

The above example transmits by sending a word file as a byte array. You do not have to do it this way, but it works.

I also want to add to any one who decides to use my method, it will be at ThreadAbortException on Response .End () . This is a known issue and it does not affect anything, everything is being implemented correctly but the exception is still thrown away, so it should be caught.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -