读取文件夹下所有文件名,饼写入xml
DirectoryInfo dinfo = new DirectoryInfo(Server.MapPath("~/etao/item/"));
FileInfo[] files = dinfo.GetFiles("*.xml"); //读取item文件夹下所有文件名
FileInfo file = new FileInfo(Server.MapPath("~/etao/FullIndex.xml"));
XmlTextWriter textWriter = new XmlTextWriter(Server.MapPath("~/etao/FullIndex.xml"), Encoding.UTF8);
textWriter.WriteStartDocument();
textWriter.WriteStartElement("root");
textWriter.WriteElementString("version", "1.0");
textWriter.WriteElementString("modified", DateTime.Now.ToString());
textWriter.WriteElementString("seller_id", "官网");
textWriter.WriteElementString("cat_url", config.PayUrl + "etao/SellerCats.xml");
textWriter.WriteElementString("dir", config.PayUrl + "etao/item/");
textWriter.WriteStartElement("item_ids");
foreach (System.IO.FileInfo fi in files)
{
textWriter.WriteStartElement("outer_id");
textWriter.WriteStartAttribute("action");
textWriter.WriteString("upload");
textWriter.WriteEndAttribute();
textWriter.WriteString(fi.Name.Replace(".xml",""));
textWriter.WriteEndElement();
}
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close();
view sourceprint?<BR>
view sourceprint?写入xml后:
view sourceprint?<DIV class=cnblogs_Highlighter><PRE class=brush:csharp;gutter:false;> <?xml version="1.0" encoding="utf-8" ?>
- <root>
<version>1.0</version>
<modified>2011-7-11 15:25:46</modified>
<seller_id>官网</seller_id>
<cat_url>http:///etao/SellerCats.xml</cat_url>
<dir>http:///etao/item/</dir>
- <item_ids>
<outer_id action="upload">ID1000018289</outer_id>
<outer_id action="upload">ID1000018292</outer_id>
<outer_id action="upload">ID1000018294</outer_id>
<outer_id action="upload">ID1000018298</outer_id>
<outer_id action="upload">ID1000018299</outer_id>
<outer_id action="upload">ID1000018303</outer_id>
<outer_id action="upload">ID1000018305</outer_id>
<outer_id action="upload">ID1000018309</outer_id>
<outer_id action="upload">ID1000018412</outer_id>
<outer_id action="upload">ID1000018413</outer_id>
<outer_id action="upload">ID1000018452</outer_id>
</item_ids>
</root>
</PRE>
</DIV>
<BR>