如何对sharepoint图片库的文件夹的图片按照时间排序并分页显示
/// <summary>
/// 获取图片库第一层文件夹--根据文件夹名称排序
/// </summary>
/// <param name="siteUrl"></param>
/// <param name="weburl"></param>
/// <param name="listID"></param>
/// <returns></returns>
public List<SPFolder> GetListRootFoldersOrderByName(string siteUrl, string weburl, string listID)
{
List<SPFolder> folderList = new List<SPFolder>();
try
{
if (!string.IsNullOrEmpty(siteUrl) && !string.IsNullOrEmpty(weburl) && !string.IsNullOrEmpty(listID))
{
using (SPSite currentsite = new SPSite(siteUrl))
{
using (SPWeb currentweb = currentsite.OpenWeb(weburl))
{
Guid listGuid = new Guid(listID);
SPList list = currentweb.Lists[listGuid];
if (list != null)
{
SPFolder rootfolder = list.RootFolder;
//按照创建文件夹的时间排序
folderList = (from SPFolder fr in rootfolder.SubFolders
where fr.Name != "Forms"
orderby fr.Name ascending
select fr).ToList();
}
}
}
}
}
catch (Exception)
{
}
return folderList;
}
分页显示
/// <summary>
/// 获取图片库第一层文件夹-linq分页
/// </summary>
/// <param name="siteUrl"></param>
/// <param name="weburl"></param>
/// <param name="listID"></param>
/// <param name="pageSize"></param>
/// <param name="pageIndex"></param>
/// <param name="totalCount"></param>
/// <returns></returns>
public List<SPFolder> GetListRootFolders(string siteUrl, string weburl, string listID, int pageSize, int pageIndex, out int totalCount)
{
List<SPFolder> folderList = new List<SPFolder>();
int count = 0;
try
{
if (!string.IsNullOrEmpty(siteUrl) && !string.IsNullOrEmpty(weburl) && !string.IsNullOrEmpty(listID))
{
using (SPSite currentsite = new SPSite(siteUrl))
{
using (SPWeb currentweb = currentsite.OpenWeb(weburl))
{
Guid listGuid = new Guid(listID);
SPList list = currentweb.Lists[listGuid];
if (list != null)
{
SPFolder rootfolder = list.RootFolder;
//按照创建文件夹的时间排序
count = rootfolder.SubFolders.Count - 1;//不记录Forms
folderList = new List<SPFolder>((from SPFolder fr in rootfolder.SubFolders
where fr.Name != "Forms"
orderby fr.Properties["vti_timecreated"] descending
select fr).Skip((pageIndex - 1) * pageSize).Take(pageSize));
}
}
}
}
}
catch (Exception)
{
}
totalCount = count;
return folderList;
}
/// <summary>
/// 获取文件夹第一个图片文件
/// </summary>
/// <param name="f"></param>
/// <returns></returns>
public SPFile GetFirstImgByFolder(SPFolder f)
{
if (f.Files.Count > 0)
{
SPFile file = (from SPFile fe in f.Files
orderby fe.TimeCreated descending
select fe).FirstOrDefault();
return file;
}
return null;
}
/// <summary>
/// 获取列表文件夹下的子文件夹
/// </summary>
/// <param name="folderGuid"></param>
/// <param name="siteUrl"></param>
/// <param name="weburl"></param>
/// <param name="listID"></param>
/// <returns></returns>
public List<SPFolder> GetSubFolders(Guid folderGuid, string siteUrl, string weburl, string listID)
{
List<SPFolder> folderList = new List<SPFolder>();
try
{
if (!string.IsNullOrEmpty(siteUrl) && !string.IsNullOrEmpty(weburl) && !string.IsNullOrEmpty(listID))
{
using (SPSite currentsite = new SPSite(siteUrl))
{
using (SPWeb currentweb = currentsite.OpenWeb(weburl))
{
Guid listGuid = new Guid(listID); SPList list = currentweb.Lists[listGuid];
if (list != null)
{
SPListItem rootfolder = list.Folders[folderGuid];
if (rootfolder.Folder.Exists)
{
folderList = new List<SPFolder>((from SPFolder fr in rootfolder.Folder.SubFolders
where fr.Name != "Forms"
orderby fr.Properties["vti_timecreated"] descending
select fr)).ToList();
}
}
}
}
}
}
catch (Exception)
{ }
return folderList;
} #region//获取某个选择的文件夹下的图片
/// <summary>
/// 根据选择的文件夹获取下面的图片
/// </summary>
/// <param name="selectedFolderValueList">选中的文件夹</param>
/// <param name="splist">列表</param>
/// <returns>返回检索的数据集合</returns>
public static List<PhotoFileEntity> GetPhotoListToSelected(string selectedFolderValueList, SPList splist)
{
//返回的值申明
List<PhotoFileEntity> photolist = new List<PhotoFileEntity>();
//
try
{
//选中的文件夹
if (!string.IsNullOrEmpty(selectedFolderValueList))
{
#region//根据选择的值得到文件夹
string[] folderList = selectedFolderValueList.Split(new char[] { ',' });
#endregion #region//循环文件夹
if (folderList != null && folderList.Length > )
{
foreach (string folderguid in folderList)
{
#region//根据文件夹的guid得到第1张图片
if (!string.IsNullOrEmpty(folderguid))
{
SPListItem itemfolder = splist.Folders[new Guid(folderguid)];
//
if (itemfolder != null)
{
//文件夹
SPFolder subfolder = itemfolder.Folder;
//如果文件夹不为空
if (subfolder != null)
{
#region//读取第1张图片为文件夹显示的图片
//读取照片
List<SPFile> spfiles = (from SPFile file in subfolder.Files
orderby file.TimeCreated descending
select file).ToList();
//如果不为空
if (spfiles != null)
{
//值读取一张
foreach (SPFile spfile in spfiles)
{
#region//读取照片详细信息
PhotoFileEntity doc = new PhotoFileEntity();
//赋值
doc.FileName = spfile.Name;
//文件夹的名称
doc.FolderName = subfolder.Name;
//文件夹的相对url
doc.FolderUrl = HttpUtility.UrlEncode(subfolder.Url);
//扩展名
doc.Extension = spfile.Item["File_x0020_Type"] == null ? string.Empty :
spfile.Item["File_x0020_Type"].ToString();
//大小缩略图
string twName = doc.FileName.Replace(string.Format(".{0}", doc.Extension),
string.Format("_{0}", doc.Extension));
//缩略图的url
doc.ThumbnailUrl = string.Format("{0}/{1}/_t/{2}.jpg", subfolder.ParentWeb.Url, doc.FolderUrl, twName);
//大图的url
doc.LargeImageUrl = string.Format("{0}/{1}/_w/{2}.jpg", subfolder.ParentWeb.Url, doc.FolderUrl, twName);
//
doc.Id = spfile.UniqueId;
doc.FileUrl = subfolder.ParentWeb.Url + "/" + spfile.Url;
doc.ServerRelativeUrl = spfile.ServerRelativeUrl;
doc.TotalLength = spfile.TotalLength;
doc.TimeCreated = spfile.TimeCreated;
doc.TimeLastModified = spfile.TimeLastModified;
//如果不为空
if (spfile.Item != null)
{
//描述
doc.Description = spfile.Item["Description"] == null ? string.Empty :
spfile.Item["Description"].ToString();
//关键字
doc.KeyWords = spfile.Item["Keywords"] == null ? string.Empty :
spfile.Item["Keywords"].ToString();
//图片宽度
doc.Width = spfile.Item["ImageWidth"] == null ? : int.Parse(spfile.Item["ImageWidth"].ToString());
//图片高度
doc.Height = spfile.Item["ImageHeight"] == null ? : int.Parse(spfile.Item["ImageHeight"].ToString());
} SPUser user = spfile.Author;
//得到作者
if (user != null)
{
doc.AuthorName = user.Name;
doc.AuthorLoginName = user.LoginName;
}
//加入到集合里来
photolist.Add(doc);
#endregion }
}
#endregion
}
}
}
#endregion }
}
#endregion
}
}
catch
{
}
//return
return photolist;
}
#endregion
如何对sharepoint图片库的文件夹的图片按照时间排序并分页显示的更多相关文章
- PHP读取文件夹目录,按时间排序,大小排序,名字排序
工作中有时候会遇到文件存储数据,但是在前台显示的时候又因为没有数据库,无法使用上传或最后一次修改日期字段排序,所以有了如下代码: <?php $dir = "./";//目录 ...
- Sharepoint中有关文件夹的操作
1.GetItemsWithUniquePermissions根据返回数量和是否返回文件夹获取唯一权限的列表项集合 对于SharePoint对象模型中SPList的GetItemsWithUnique ...
- SharePoint REST API - 文件夹和文件
博客地址:http://blog.csdn.net/FoxDave 本篇讲述如何通过REST操作文件夹和文件. 使用REST操作文件夹 在你知道某个文档库中的文件夹的URL时,可以使用如下的代码获 ...
- java 把一个文件夹里图片复制到另一个文件夹里
import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.ut ...
- 读取assets文件夹下图片(ods_interview)
今天看了一道题,现在总结一下里面使用到的知识点: 1.assets文件的访问: 原文出处:http://blog.csdn.net/fengyuzhengfan/article/details/383 ...
- PDF 补丁丁 0.4.1.804 测试版发布:合并文件夹的图片和PDF文件,自由生成多层次书签
新的测试版增强了合并文件的功能,可以合并文件夹内的图片和PDF文件,还可以在合并文件列表上直接指定与合并文件对应的PDF书签标题.通过拖放文件项目生成多层次的PDF书签.如下图所示: 另外,新的测试版 ...
- angular调用WCF服务,读取文件夹下图片显示列表,下载另存为图片
读取文件夹下的文件 public string ReadImagesPaths() { string result = string.Empty; try { string path = System ...
- du---查看文件夹大小-并按大小进行排序
使用df 命令查看当前磁盘使用情况: df -lh [root@gaea-dev-xjqxz-3 ~]$ df -lh Filesystem Size Used Avail Use% Mounted ...
- [Linux] du-查看文件夹大小-并按大小进行排序
reference : http://blog.csdn.net/jiaobuchong/article/details/50272761# 某天,我想检查一下电脑硬盘的的使用情况,作为一个命令控,废 ...
随机推荐
- Mybatis之Oracle增删查改示例--转
http://blog.csdn.net/bingjie1217/article/details/21088431?utm_source=tuicool&utm_medium=referral ...
- Struts2整合Hibernate3实现用户登录功能
所用技术:struts2 ,hibernate,jsp,mysql 本DEMO仅仅实现用户登录功能,采用MVC思想,自己也觉得相对是比较简单,比较容易理解数据流向的一个例子,通过整合这个过程,能够清晰 ...
- Java性能优化
作者:禅楼望月(http://www.cnblogs.com/yaoyinglong) 注:里面的测试结果会因电脑配置的不同而有所差异!!! 1. 为一些集合定义初始化大小 List.Set.Map都 ...
- Java判断回文数算法简单实现
好久没写java的代码了, 今天闲来无事写段java的代码,算是为新的一年磨磨刀,开个头,算法是Java判断回文数算法简单实现,基本思想是利用字符串对应位置比较,如果所有可能位置都满足要求,则输入的是 ...
- 使用Spark分析拉勾网招聘信息(四): 几个常用的脚本与图片分析结果
概述 前一篇文章,已经介绍了BMR的基础用法,再结合Spark和Scala的文档,我想应该是可以开始你的数据分析之路的.这一篇文章,着重进行一些简单的思路上的引导和分析.如果你分析招聘数据时,卡在了某 ...
- img[src*="same"]{}
假如你有一组图片,你想选择其中一些名字中带有same的图片,那么你就可以用这种写法,这里的意思就是选择所有正确路径下名字中带有same的图片文件. 譬如说:me_same.png,you_same.p ...
- [Asp.net 5] DependencyInjection项目代码分析
最近在研究开源代码,正好发现Asp.net5的源码,下载地址:https://github.com/aspnet. 今天主要讲的是DependencyInjection这部分,抛砖引玉,供大家参考,也 ...
- Castle ActiveRecord框架学习(一)
一.Active Record(活动记录)模式 Active Record是业务逻辑层中(<企业应用架构模式>将该模式归为数据源模式)常用的一种框架模式,尤其在底层数据库模型匹配业务模型时 ...
- C#DateTimePicker控件问题
DateTimPicker控件在遇到29这样特殊的日期,选择时可能会出现 解决方案:在属性中把Value值设置为除29日外的其他日期或者在代码中直接设置Value值:DateTimePicker1 = ...
- XMPP客户端开发(1)--连接和登录
Smack可用于XMPP客户端的开发,下载Smack,将相关jar文件导入后,即可以开始XMPP客户端的开发. 以下代码实现了客户端连接Tigase服务器,并根据用户名和密码登录. package X ...