[英]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.