Error : http query string is too long

822 Views Asked by At

I use the below code in mvc to download Excel file but it shows error query string too long.

public ActionResult Download(string input)
{
    Response.Clear();
    Response.ClearHeaders();
    Response.ClearContent();
    Response.Buffer = true;
    Response.AddHeader("Content-Disposition", "attachment; filename= download.xlsx");
    Response.AddHeader("Content-Type", "application/Excel");
    Response.ContentType = "application/vnd.ms-excel";
    Response.WriteFile(input);
    Response.End();

    return Content(String.Empty);
}
1

There are 1 best solutions below

2
On BEST ANSWER

This code works for me for PDF:

public FileStreamResult DownnloadPDF(int id)
        {Document document = new Document();

            MemoryStream stream = new MemoryStream();
                PdfWriter pdfWriter = PdfWriter.GetInstance(document, stream);
                pdfWriter.CloseStream = false;

                document.Open();

                formatPDF(document, model);

document.Close();

            stream.Flush(); //Always catches me out
            stream.Position = 0; //Not sure if this is required

            return File(stream, "application/pdf", "title" + ".pdf");
        }

I really think that your ActionResult will not work.