i have this function for generating an xml file.. the problem is that when i download the generated file, i have my xml correctly formatted but at the end of this also the html source code of the page where i have clicked the button for generate this. What is the problem? Here the source code:
protected void lnkEsporta_Click(object sender, EventArgs e)
{
List<Eventi> lista_eventi = //load list
string filename = "~/data/eventi.xml";
XmlTextWriter tw = new XmlTextWriter(Server.MapPath(filename), Encoding.GetEncoding("ISO-8859-1"));
tw.Flush();
tw.Formatting = Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("wrapper");
tw.WriteElementString("project", GetDao().Get<Progetti, Int32>(lista_eventi[0].idprogetto).nome);
tw.WriteStartElement("events");
foreach (Eventi evento in lista_eventi)
{
tw.WriteStartElement("event");
tw.WriteElementString("idEv", evento.idev.ToString());
tw.WriteElementString("data", evento.DataInizio.ToString());
tw.WriteElementString("sede", evento.sede.ToString());
tw.WriteElementString("location", evento.location.ToString());
tw.WriteElementString("video", evento.video ? "True" : "False");
tw.WriteElementString("tutors", evento.tutors.ToString());
tw.WriteElementString("technicians", evento.technicians.ToString());
tw.WriteStartElement("aule");
List<Aule> lista_aule = //load list
foreach (Aule aula in lista_aule)
{
tw.WriteElementString("aula", aula.descrizione.ToString(), aula.idaula.ToString());
}
tw.WriteEndElement();
tw.WriteEndElement(); //end of source event
}
tw.WriteEndElement();//end of source events
tw.WriteEndElement();//end of source wrapper
tw.WriteEndDocument();//end of source tag
tw.Close();
Response.ClearContent();
//Response.End();
Response.Clear();
Response.StatusCode = 200;
Response.AddHeader("content-disposition", "attachment; filename=" + filename);
Response.AddHeader("Content-Transfer-Encoding", "binary");
//Response.AddHeader("Content-Length", _Buffer.Length.ToString());
Response.ContentType = "application-download";
Response.TransmitFile(Server.MapPath(filename));
}
i have at the beginning my xml and after this it starts with page source code... what can i do? thank you very much for your help!