Okay so i have page which bacially gets a file as a Byte[] from a webservice which I then give a Save/Cancel dialogue to the user to save that file. This file can either be xml or cvs format. When the file is downloaded the file is incomplete e.g. This is what the file should have:
USD,EUR,Euro,1.2,1.1,11/15/2009,15:23:27
USD,AUD,Australian,1.25,1.15,11/15/2009,15:23:27
but when saved from the browser it only has::
USD,EUR,Euro,1.2,1.1,11/15/2009,15:23:27
USD,AUD,Australian,1.25,1.
here is my code:
Response.Buffer = true;
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AddHeader("Content-Length", MyFile.Length.ToString());
FileInfo file = new FileInfo(fileName);
Response.ContentType = Utility.ReturnExtension(file.Extension.ToLower());
Response.BinaryWrite(MyFile);
Response.Flush();
Response.Close();
Response.End();
I have already made sure the byte[] i am getting from webservice is okay by writing the file
on my machine using following code:
StreamWriter writer = null;
string blah = System.Text.ASCIIEncoding.ASCII.GetString(MyFile);
writer = File.CreateText(Server.MapPath(filePath+fileName));
writer.Write(blah);
writer.Close();
writer.Dispose();
If I remove the Close() and End() then the whole file is rendered with some HTML code from the page. I get complete file(only XML format) if i first create/write file on my local machine and then do Response.TransmitFile(file).
I am not sure what i am doing wrong. Maybe its just something very simple. Any help will be greatly appreciated