File Downlaod

I am creating a .csv file on my server then I want to be able to let the user download it.  I have this code and it creates a file but instead of letting them download it displays it on the browser

            // create a writer and open the file
            TextWriter tw = new StreamWriter(@"C:\Inetpub\websites\website.net\app_data\downloads\work.csv");

            // write a line of text to the file
            tw.WriteLine("test,123,99.85,$100.34");

            // close the stream
            tw.Close();


            Response.Write("Download");
            Response.ContentType = "text/csv";
            Response.AddHeader("content-disposition", "attachment; filename=work.csv");

            FileStream sourceFile = new FileStream(@"C:\Inetpub\websites\website.net\app_data\downloads\work.csv", FileMode.Open);
            long FileSize;
            FileSize = sourceFile.Length;
            byte[] getContent = new byte[(int)FileSize];
            sourceFile.Read(getContent, 0, (int)sourceFile.Length);
            sourceFile.Close();

               Response.BinaryWrite(getContent);
Charles BaldoSoftware DeveloperAsked:
Who is Participating?
 
AlsaeedCommented:
0
 
Paul MacDonaldDirector, Information SystemsCommented:
You proably want to
Response.Redirect(C:\Inetpub\websites\website.net\app_data\downloads\work.csv")
0
 
alphacoderCommented:
change your content type from text/csv to application/unknown
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.