Web如何下载XML 文件 c#?
- 提问者网友:姑娘长的好罪过
- 2021-07-29 07:44
- 五星知识达人网友:上分大魔王
- 2021-07-29 07:56
string destFileName = "ok.xml";
destFileName = Server.MapPath(".") + "\\"+destFileName;
destFileName = Server.UrlDecode(destFileName);
if (File.Exists(destFileName))
{
FileInfo fi = new FileInfo(destFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(destFileName), System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", fi.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(destFileName);
Response.Flush();
Response.End();
}
else
{
Response.Write("<script langauge=javascript>alert('文件不存在!');history.go(-1);</script>");
Response.End();
// 适用于 TXT 文本和 XML 下载。 web 方式 通常下载是 会打开,以上方法会另存为。!
好就顶!