惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Last Watchdog
The Last Watchdog
AI
AI
Recent Announcements
Recent Announcements
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Stack Overflow Blog
Stack Overflow Blog
V
Visual Studio Blog
J
Java Code Geeks
TaoSecurity Blog
TaoSecurity Blog
L
LangChain Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
Microsoft Security Blog
Microsoft Security Blog
量子位
T
Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - Franky
博客园 - 聂微东
L
LINUX DO - 最新话题
Security Archives - TechRepublic
Security Archives - TechRepublic
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
The GitHub Blog
The GitHub Blog
C
Check Point Blog
宝玉的分享
宝玉的分享
G
Google Developers Blog
Spread Privacy
Spread Privacy
Cloudbric
Cloudbric
SecWiki News
SecWiki News
有赞技术团队
有赞技术团队
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
美团技术团队
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
A
Arctic Wolf
P
Privacy & Cybersecurity Law Blog
P
Palo Alto Networks Blog
H
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
About on SuperTechFans
N
Netflix TechBlog - Medium
罗磊的独立博客
月光博客
月光博客

博客园 - 冷火

Lucene.Net学习 Argotic Syndication Framework生成RSS - 冷火 Confirm GridView Deletes with the ModalPopupExtender 如何在C#中实现图片缩放 [ASP.NET] 限制上传文件类型的两种方法 asp.net采集 在C#怎用一条正则表达式验证用逗号隔开的email地址 关于LumiSoft.Net.POP3.Client接收邮件例子(包括附件) dhtmlXTreeprofessional DateDiff Datagridview下一行下一行 GridView控件修改、删除示例(修改含有DropDownList控件) - 冷火 - 博客园 局域网QQ第三版(V1.4) asp.net+JSON+AJAX(基于prototype1.4)做无刷新的2级DropDownList - 冷火 - 博客园 非常好的菜单效果(Accordion风格) 静功解决失眠的问题 ASP.NET中文验证码详解 log4net Config Examples 对XAML进行编辑的辅助类(XamlHelper)
asp.net导出xml文件 - 冷火 - 博客园
冷火 · 2009-06-22 · via 博客园 - 冷火

protected void Button1_Click(object sender, EventArgs e)
    {
        Random random=new Random();
        int rnumber=random.Next(1, 100);
        string outPutName = DateTime.Now.ToString("yyyyMMddhhmmss") + rnumber.ToString();
        HttpResponse resp;
        resp = Page.Response;
        resp.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
        resp.ContentType = "text/xml";
        resp.AddHeader("Content-Disposition",
"attachment; filename=" + System.Web.HttpUtility.UrlEncode(outPutName, System.Text.Encoding.UTF8) + ".xml");

        this.EnableViewState = false;

        DataTable dt = new DataTable();
        if (!string.IsNullOrEmpty(txtDONos.Text.Trim()))
        {
            DistributeOrderBLL doBll = new DistributeOrderBLL();
            string strDistributeOrderNos = txtDONos.Text.Trim();
            dt = doBll.GetDistributeOrderByDistributeOrderNos

(strDistributeOrderNos);
        }
        DataSet ds = new DataSet();
        ds.Tables.Add(dt);

        StringBuilder xmlData = new StringBuilder();
        xmlData.AppendLine(@"<?xml version='1.0' encoding='UTF-8' ?>");
        xmlData.AppendLine(@"<root>");
        foreach (DataRow dr in dt.Rows)
        {
            xmlData.AppendLine(@"<person");
            xmlData.AppendLine(@" id='" + dr["Name"] + "' ");
            xmlData.AppendLine(@">");

            xmlData.AppendLine(@"<name>" + dr["Name"] + "</name>");
            xmlData.AppendLine(@"<address>" + dr["Street"] + "</address>");
            xmlData.AppendLine(@"<city>" + dr["CityName"] + "</city>");
            xmlData.AppendLine(@"</person>");
        }
        xmlData.AppendLine(@"</root>");
        Response.Write(xmlData.ToString());

        Response.End();

    }

 另外一种办法

 public void toMakXmlFile(ArrayList lfname, ArrayList lfile,string xmlName)
        {

            System.IO.StringWriter sw = new System.IO.StringWriter();
            xmlW = new XmlTextWriter(sw);
            xmlW.Formatting = Formatting.Indented;
            xmlW.WriteStartElement("Lables");
            for (int i = 0; i < lfile.Count; i++)
            {
                xmlW.WriteStartElement("LableItem");

                xmlW.WriteStartElement("lfile");
                xmlW.WriteAttributeString("lfname", (string)lfname[i]);
                xmlW.WriteString((string)lfile[i]);
                xmlW.WriteEndElement();

                xmlW.WriteEndElement();
            }
            xmlW.WriteEndElement();

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8"); // 中文
            HttpContext.Current.Response.AppendHeader("content-disposition", "attachment;filename=\"" + xmlName + ".xml\"");
            HttpContext.Current.Response.Write(sw.ToString());
            HttpContext.Current.Response.End();

        }

 读取的一种办法

 //读取xml文件
                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.Load(e.FullPath);
                            XmlNode xn = xmlDoc.SelectSingleNode("root");
                            XmlNodeList xnl = xn.ChildNodes;
                            foreach (XmlNode xnf in xnl)
                            {
                                XmlElement xe = (XmlElement)xnf;
                                XmlNodeList xnf1 = xe.ChildNodes;
                                string name = xnf1.Item(0).InnerText;
                                string address = xnf1.Item(1).InnerText;
                                string city = xnf1.Item(2).InnerText;
                                string state = xnf1.Item(3).InnerText;
                                string postcode = xnf1.Item(4).InnerText;
                                string country = xnf1.Item(5).InnerText;
                                string phone1 = xnf1.Item(6).InnerText;

                             }