只好写这么个东西,再用XSL显示了。
代码还没完全写好,往集合中添加ITEM时,后面的项总会把前面的几个覆盖掉,最终就只剩下最后一个ITEM了,不过COUNT是对的。
贴一部分代码:
搜索指定目录的文件
下面的是生成RSS的类,不过有问题,再向频道添加ITEM的时候,后一个会覆盖前一个。
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using System.IO;
6using Rss;
7namespace buildSiteMap
8{
9 public class buildxml
10 {
11 private seachFiles sf = new seachFiles();
12 private string siteurl;
13 private string filepath;
14 public buildxml()
15 {
16 sf.Filepath = "";
17 sf.Filetypes = "";
18 filepath = "";
19 siteurl = "";
20 }
21 public buildxml(string filep,string filet,string url)
22 {
23 sf.Filepath = filep;
24 sf.Filetypes = filet;
25 siteurl=url;
26 filepath = filep;
27 filepath = this.ismenusite(filepath);
28 }
29 public string Siteurl
30 {
31 get { return this.siteurl; }
32 set { this.siteurl = value; }
33 }
34 public bool savexml()
35 {
36 try
37 {
38 Rss.RssFeed rf = new RssFeed();
39 rf.Encoding = System.Text.Encoding.GetEncoding("gb2312");
40 rf.Version = RssVersion.RSS20;
41 Rss.RssItem ri = new RssItem();
42 Rss.RssChannel rc = new RssChannel();
43 rc.Title = "china tour";
44 rc.Description = "china tour|tibet tour|sichuan tour";
45 siteurl = this.getsiteurl(siteurl);
46 siteurl = this.iswebsite(siteurl);
47 rc.Link = new Uri(siteurl);
48
49 rc.PubDate = DateTime.Now;
50 System.Collections.ArrayList arr = new System.Collections.ArrayList();
51 arr = sf.getFilePaths();
52 string tempstr = "";
53 foreach(FileInfo fi in arr)
54 {
55 System.Console.Out.WriteLine(fi.Name);
56 ri.Title = fi.Name.ToString();// this.getfilename();
57 tempstr = fi.FullName.ToString();
58 tempstr = tempstr.Replace(filepath, siteurl);
59 ri.Link = new Uri(tempstr);
60 ri.PubDate = fi.LastWriteTime;
61 rc.Items.Add(ri);
62 }
63 rf.Channels.Add(rc);
64 string sitename = this.getsitename(siteurl.ToString());
65 rf.Write(filepath+sitename+".xml");
66 }
67 catch (Exception ex)
68 {
69 System.Console.Out.Write("保存RSS时出错"+ex.Message.ToString());
70 return false;
71 }
72 return true;
73 }
74 private string iswebsite(string linkurl)
75 {
76 string c=linkurl.Substring(linkurl.Length - 1);
77 return c.Equals("/") ? linkurl : linkurl + "/";
78 }
79 private string ismenusite(string linkurl)
80 {
81 string c = linkurl.Substring(linkurl.Length - 1);
82 return c.Equals("\\") ? linkurl : linkurl + "\\";
83 }
84 private string getsitename(string siteurl)
85 {
86
87 return siteurl.Split('.')[1].ToString();
88 }
89 private string getsiteurl(string siteurl)
90 {
91 return siteurl == "" ? "http://www.lutoo.com" : siteurl;
92 }
93 private string getfilename(string filename)
94 {
95 return filename.Split('.')[0].ToString();
96 }
97 }
98}
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using System.IO;
6using Rss;
7namespace buildSiteMap
8{
9 public class buildxml
10 {
11 private seachFiles sf = new seachFiles();
12 private string siteurl;
13 private string filepath;
14 public buildxml()
15 {
16 sf.Filepath = "";
17 sf.Filetypes = "";
18 filepath = "";
19 siteurl = "";
20 }
21 public buildxml(string filep,string filet,string url)
22 {
23 sf.Filepath = filep;
24 sf.Filetypes = filet;
25 siteurl=url;
26 filepath = filep;
27 filepath = this.ismenusite(filepath);
28 }
29 public string Siteurl
30 {
31 get { return this.siteurl; }
32 set { this.siteurl = value; }
33 }
34 public bool savexml()
35 {
36 try
37 {
38 Rss.RssFeed rf = new RssFeed();
39 rf.Encoding = System.Text.Encoding.GetEncoding("gb2312");
40 rf.Version = RssVersion.RSS20;
41 Rss.RssItem ri = new RssItem();
42 Rss.RssChannel rc = new RssChannel();
43 rc.Title = "china tour";
44 rc.Description = "china tour|tibet tour|sichuan tour";
45 siteurl = this.getsiteurl(siteurl);
46 siteurl = this.iswebsite(siteurl);
47 rc.Link = new Uri(siteurl);
48
49 rc.PubDate = DateTime.Now;
50 System.Collections.ArrayList arr = new System.Collections.ArrayList();
51 arr = sf.getFilePaths();
52 string tempstr = "";
53 foreach(FileInfo fi in arr)
54 {
55 System.Console.Out.WriteLine(fi.Name);
56 ri.Title = fi.Name.ToString();// this.getfilename();
57 tempstr = fi.FullName.ToString();
58 tempstr = tempstr.Replace(filepath, siteurl);
59 ri.Link = new Uri(tempstr);
60 ri.PubDate = fi.LastWriteTime;
61 rc.Items.Add(ri);
62 }
63 rf.Channels.Add(rc);
64 string sitename = this.getsitename(siteurl.ToString());
65 rf.Write(filepath+sitename+".xml");
66 }
67 catch (Exception ex)
68 {
69 System.Console.Out.Write("保存RSS时出错"+ex.Message.ToString());
70 return false;
71 }
72 return true;
73 }
74 private string iswebsite(string linkurl)
75 {
76 string c=linkurl.Substring(linkurl.Length - 1);
77 return c.Equals("/") ? linkurl : linkurl + "/";
78 }
79 private string ismenusite(string linkurl)
80 {
81 string c = linkurl.Substring(linkurl.Length - 1);
82 return c.Equals("\\") ? linkurl : linkurl + "\\";
83 }
84 private string getsitename(string siteurl)
85 {
86
87 return siteurl.Split('.')[1].ToString();
88 }
89 private string getsiteurl(string siteurl)
90 {
91 return siteurl == "" ? "http://www.lutoo.com" : siteurl;
92 }
93 private string getfilename(string filename)
94 {
95 return filename.Split('.')[0].ToString();
96 }
97 }
98}