return XML file to user
I am creating a XML file which I want to retu开发者_开发百科rn to the user, when the user goes to a specified location. I have thought of something like:
return new FileStream("questions.xml",FileMode.Open);
Is this the proper code, or how would you return a file?
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
var file = Server.MapPath("~/questions.xml");
Response.WriteFile(file);
Response.ContentType = "text/xml";
Response.AddHeader("Content-Disposition", "attachment; filename=questions.xml");
}
精彩评论