繁体   English   中英

在服务器上创建一个xml文件并下载到客户端asp.net和C#

[英]create a xml file on server and download to client asp.net and c#

我尝试使用c#在asp.net页面中创建XML类型文件并下载到客户端,这是我的代码,但是它不起作用。

public void SaveKml()
{
    XmlDocument doc = new XmlDocument();
    //create xml/kml document here
    StringBuilder kmlpath = new StringBuilder();

    kmlpath.Append("nameG");
    kmlpath.Append("_");
    kmlpath.Append(parYE1);
    kmlpath.Append("_");
    kmlpath.Append(parID1);
    kmlpath.Append(".kml"); // google earth 

    string path1 = @"~/App_Data/" + kmlpath.ToString();

    doc.Save(HttpContext.Current.Server.MapPath(path1));
    FileInfo fi = new FileInfo(path1);

    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ContentType = "application/octet-stream";
    HttpContext.Current.Response.AddHeader("content - disposition", "attachment; filename =" +fi.Name);
    HttpContext.Current.Response.AppendHeader("Content-Length", fi.Length.ToString());
    HttpContext.Current.Response.TransmitFile(fi.FullName,0,fi.Length);
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.End();
}

看来您的XML文件为空,您需要在此处指定根节点,请参考下面的链接: https : //msdn.microsoft.com/zh-cn/library/dw229a22(v=vs.110).aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM