sharepoint2010获取最新发布文档并按照时间排序显示
2012-07-12 10:55
393 查看
首先,这个sp中内容查询webparts也是可以完成这样的功能,只需要自己配置就好了,但是如果你需要更炫的效果,可以自己手动获取
代码如下
1 protected DataTable table = new DataTable();
2 protected void Page_Load(object sender, EventArgs e)
3 {
4 if (!IsPostBack)
5 {
6 table.Columns.Add(new DataColumn("linkurl"));
7 table.Columns.Add(new DataColumn("title"));
8 table.Columns.Add(new DataColumn("imgurl"));
9 table.Columns.Add(new DataColumn("author"));
10 table.Columns.Add(new DataColumn("authorID"));
11 table.Columns.Add(new DataColumn("date", Type.GetType("System.DateTime")));
12 table.Columns.Add(new DataColumn("folder"));
13 table.Columns.Add(new DataColumn("folderurl"));
14 using (SPWeb web = SPContext.Current.Site.OpenWeb())
15 {
16 for (int i = 0; i < web.Lists.Count; i++)
17 {
18 try
19 {
20 SPDocumentLibrary list = (SPDocumentLibrary)web.Lists[i];
21 SPFolder folder = list.RootFolder;
22 if (folder.Name != "fpdatasources" && folder.Name != "masterpage" && folder.Name!="Documents")
23 {
24 SPFileCollection files = folder.Files;
25 foreach (SPFile file in files)//获取第一级文件也就是docs中的文件名
26 {
27 DataRow row = table.NewRow();
28 row["linkurl"] = file.Url;
29 row["title"] = file.Title;
30 row["imgurl"] = file.IconUrl;
31 row["author"] = file.Author.Name;
32 row["authorID"] = file.Author.ID;
33 row["date"] = file.TimeCreated;
34 row["folder"] = folder.Name;
35 row["folderurl"] = folder.ServerRelativeUrl;
36 table.Rows.Add(row);
37 }
38 EnumerateFolders(folder.SubFolders);
39 }
40 }
41 catch (Exception ex)
42 {
43 }
44 }
45 }
46 DataView Docs = new DataView(table);
47 Docs.Sort = "date Desc";
48 string filter = string.Empty;
49 string delimiter = string.Empty;
50 int numDocs =10;
51 numDocs = Math.Min(numDocs, Docs.Count);
52 for (int i = 0; i < numDocs; i++)
53 {
54 filter += delimiter + "'" + Docs[i]["linkurl"].ToString() + "'"; delimiter = ",";
55 }
56 if (filter.Length > 0)
57 {
58 Docs.RowFilter = "linkurl in (" + filter + ")";
59 }
60 rptList.DataSource = Docs;
61 rptList.DataBind();
62 }
63 }
64
65 //下面的方法是迭代获取文档库中的所有文件夹及其文件夹内的文件
66 private void EnumerateFolders(SPFolderCollection folders)
67 {
68 foreach (SPFolder subFolder in folders)//获取文件夹中的文件
69 {
70 if ( subFolder.Name != "Forms" && subFolder.Name != "masterpage" && subFolder.Name!="fpdatasources")
71 {
72 SPFileCollection subFiles = subFolder.Files;
73 foreach (SPFile file in subFiles)
74 {
75 DataRow row = table.NewRow();
76 row["linkurl"] = file.Url;
77 row["title"] = file.Title;
78 row["imgurl"] = file.IconUrl;
79 row["author"] = file.Author.Name;
80 row["authorID"] = file.Author.ID;
81 row["date"] = file.TimeCreated;
82 row["folder"] = subFolder.Name;
83 row["folderurl"] = subFolder.Url;
84 table.Rows.Add(row);
85 }
86 SPFolderCollection subFolders = subFolder.SubFolders;//获取文件夹中的子文件夹
87 EnumerateFolders(subFolders);
88 }
89 }
90 }
代码如下
1 protected DataTable table = new DataTable();
2 protected void Page_Load(object sender, EventArgs e)
3 {
4 if (!IsPostBack)
5 {
6 table.Columns.Add(new DataColumn("linkurl"));
7 table.Columns.Add(new DataColumn("title"));
8 table.Columns.Add(new DataColumn("imgurl"));
9 table.Columns.Add(new DataColumn("author"));
10 table.Columns.Add(new DataColumn("authorID"));
11 table.Columns.Add(new DataColumn("date", Type.GetType("System.DateTime")));
12 table.Columns.Add(new DataColumn("folder"));
13 table.Columns.Add(new DataColumn("folderurl"));
14 using (SPWeb web = SPContext.Current.Site.OpenWeb())
15 {
16 for (int i = 0; i < web.Lists.Count; i++)
17 {
18 try
19 {
20 SPDocumentLibrary list = (SPDocumentLibrary)web.Lists[i];
21 SPFolder folder = list.RootFolder;
22 if (folder.Name != "fpdatasources" && folder.Name != "masterpage" && folder.Name!="Documents")
23 {
24 SPFileCollection files = folder.Files;
25 foreach (SPFile file in files)//获取第一级文件也就是docs中的文件名
26 {
27 DataRow row = table.NewRow();
28 row["linkurl"] = file.Url;
29 row["title"] = file.Title;
30 row["imgurl"] = file.IconUrl;
31 row["author"] = file.Author.Name;
32 row["authorID"] = file.Author.ID;
33 row["date"] = file.TimeCreated;
34 row["folder"] = folder.Name;
35 row["folderurl"] = folder.ServerRelativeUrl;
36 table.Rows.Add(row);
37 }
38 EnumerateFolders(folder.SubFolders);
39 }
40 }
41 catch (Exception ex)
42 {
43 }
44 }
45 }
46 DataView Docs = new DataView(table);
47 Docs.Sort = "date Desc";
48 string filter = string.Empty;
49 string delimiter = string.Empty;
50 int numDocs =10;
51 numDocs = Math.Min(numDocs, Docs.Count);
52 for (int i = 0; i < numDocs; i++)
53 {
54 filter += delimiter + "'" + Docs[i]["linkurl"].ToString() + "'"; delimiter = ",";
55 }
56 if (filter.Length > 0)
57 {
58 Docs.RowFilter = "linkurl in (" + filter + ")";
59 }
60 rptList.DataSource = Docs;
61 rptList.DataBind();
62 }
63 }
64
65 //下面的方法是迭代获取文档库中的所有文件夹及其文件夹内的文件
66 private void EnumerateFolders(SPFolderCollection folders)
67 {
68 foreach (SPFolder subFolder in folders)//获取文件夹中的文件
69 {
70 if ( subFolder.Name != "Forms" && subFolder.Name != "masterpage" && subFolder.Name!="fpdatasources")
71 {
72 SPFileCollection subFiles = subFolder.Files;
73 foreach (SPFile file in subFiles)
74 {
75 DataRow row = table.NewRow();
76 row["linkurl"] = file.Url;
77 row["title"] = file.Title;
78 row["imgurl"] = file.IconUrl;
79 row["author"] = file.Author.Name;
80 row["authorID"] = file.Author.ID;
81 row["date"] = file.TimeCreated;
82 row["folder"] = subFolder.Name;
83 row["folderurl"] = subFolder.Url;
84 table.Rows.Add(row);
85 }
86 SPFolderCollection subFolders = subFolder.SubFolders;//获取文件夹中的子文件夹
87 EnumerateFolders(subFolders);
88 }
89 }
90 }
相关文章推荐
- 一个获取手机应用并且按照安装的最新更新时间排序的demo
- 织梦dedecms TAG列表按最新发布时间排序的解决方法
- android获取SDCard中照片并按照时间顺序显示
- 如何对sharepoint图片库的文件夹的图片按照时间排序并分页显示
- iOS 获取当前时间,并按照要求格式显示
- 判断手机号的输入是否正确、获取当前的时间以及显示距离上次发布有多久的时间
- Oracle 数据库 排序(前三条按浏览量排序,后面的按照发布时间排序)
- android获取SDCard中照片并按照时间顺序显示
- Sql语句 表中相同的记录(某个字段)只显示一条,按照时间排序显示最大或最小
- android获取SDCard中照片并按照时间顺序显示
- 让你的网站数据对搜索引擎来说按照最新时间排序,正常用户排序按照自己设定的方式排序
- 批处理 按照文件的创建时间排序 获取第一文件
- 批处理 按照文件的创建时间排序 获取第一文件
- android获取SDCard中照片并按照时间顺序显示
- 获取指定字段的首字母,并按照字母排序
- C#中获取和显示系统的日期和时间
- JN项目-对社团申请进行排序,按照申请时间和审核时间降序
- DEDECMS调用最新评论包括评论时间及发布作者
- asp fso读取文件夹,如何按照(1:按创建时间 2:按访问时间 3:按修改时间 4:按名称)排序(2008-09-18,11:19:18)
- List<Map<String,Object>>按照子元素中的时间排序