System.Web.HttpResponse.TransmitFile C# (CSharp) Method

TransmitFile() private method

private TransmitFile ( System.Web.Hosting.VirtualFile vf ) : void
vf System.Web.Hosting.VirtualFile
return void
		internal void TransmitFile (VirtualFile vf)
		{
			TransmitFile (vf, false);
		}

Same methods

HttpResponse::TransmitFile ( System.Web.Hosting.VirtualFile vf, bool final_flush ) : void
HttpResponse::TransmitFile ( string filename ) : void
HttpResponse::TransmitFile ( string filename, bool final_flush ) : void
HttpResponse::TransmitFile ( string filename, long offset, long length ) : void

Usage Example

        public ActionResult ExportCSV(string emailList)
        {
            string FilePath = Server.MapPath("/App_Data/");
            string FileName = "EmailList.csv";

            System.IO.File.WriteAllText(FilePath + FileName, emailList);

            System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            response.ClearContent();
            response.Clear();
            response.ContentType = "text/csv";
            response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
            response.TransmitFile(FilePath + FileName);
            response.Flush();
            System.IO.File.Delete(FilePath + FileName); // Deletes the file on server

            response.End();
            List <string> listOfEmails = emailList.Split(',').ToList();

            foreach (var emailName in listOfEmails)
            {
                //Takes each email in list and searches for it on the JPStudents table and finds the associated ApplicationUserID.
                //Then calls the UpdateLatestContact method on each ApplicationUserID.
                var userId = db.JPStudents.Where(x => x.JPEmail == emailName).First().ApplicationUserId.ToString();
                UpdateLatestContact(userId);
            }
            return(RedirectToAction("Index"));
        }
All Usage Examples Of System.Web.HttpResponse::TransmitFile