开发者

return XML file to user

开发者 https://www.devze.com 2023-02-23 08:55 出处:网络
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:

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

精彩评论

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

关注公众号