开发者

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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜