0

I have below code in asp.net

 GetObjectResponse resp = Media.ReadS3Object("data", strKey);
            StreamReader sr = new StreamReader(resp.ResponseStream);

            //Prompt download:
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = resp.ContentType; // "text/csv;";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}", fname));
            HttpContext.Current.Response.BinaryWrite(UTF8Encoding.Convert(Encoding.UTF8, Encoding.Unicode, Encoding.UTF8.GetBytes(sr.ReadToEnd())));
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();

it downloads file, how can I achieve samething through mvc. Thanks

Md. Parvez Alam
  • 3,795
  • 2
  • 27
  • 74

1 Answers1

0

Set the ActionResult to return a file.

public ActionResult DownloadFile(string strKey) {
    GetObjectResponse resp = Media.ReadS3Object("data", strKey);
    StreamReader sr = new StreamReader(resp.ResponseStream);


    return File(sr, resp.ContentType, fname);
}
Mad Myche
  • 1,040
  • 1
  • 7
  • 15