/// <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图片库的文件夹的图片按照时间排序并分页显示的更多相关文章

  1. PHP读取文件夹目录,按时间排序,大小排序,名字排序

    工作中有时候会遇到文件存储数据,但是在前台显示的时候又因为没有数据库,无法使用上传或最后一次修改日期字段排序,所以有了如下代码: <?php $dir = "./";//目录 ...

  2. Sharepoint中有关文件夹的操作

    1.GetItemsWithUniquePermissions根据返回数量和是否返回文件夹获取唯一权限的列表项集合 对于SharePoint对象模型中SPList的GetItemsWithUnique ...

  3. SharePoint REST API - 文件夹和文件

    博客地址:http://blog.csdn.net/FoxDave 本篇讲述如何通过REST操作文件夹和文件. 使用REST操作文件夹 在你知道某个文档库中的文件夹的URL时,可以使用如下的代码获 ...

  4. java 把一个文件夹里图片复制到另一个文件夹里

    import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.ut ...

  5. 读取assets文件夹下图片(ods_interview)

    今天看了一道题,现在总结一下里面使用到的知识点: 1.assets文件的访问: 原文出处:http://blog.csdn.net/fengyuzhengfan/article/details/383 ...

  6. PDF 补丁丁 0.4.1.804 测试版发布:合并文件夹的图片和PDF文件,自由生成多层次书签

    新的测试版增强了合并文件的功能,可以合并文件夹内的图片和PDF文件,还可以在合并文件列表上直接指定与合并文件对应的PDF书签标题.通过拖放文件项目生成多层次的PDF书签.如下图所示: 另外,新的测试版 ...

  7. angular调用WCF服务,读取文件夹下图片显示列表,下载另存为图片

    读取文件夹下的文件 public string ReadImagesPaths() { string result = string.Empty; try { string path = System ...

  8. du---查看文件夹大小-并按大小进行排序

    使用df 命令查看当前磁盘使用情况: df -lh [root@gaea-dev-xjqxz-3 ~]$ df -lh Filesystem Size Used Avail Use% Mounted ...

  9. [Linux] du-查看文件夹大小-并按大小进行排序

    reference : http://blog.csdn.net/jiaobuchong/article/details/50272761# 某天,我想检查一下电脑硬盘的的使用情况,作为一个命令控,废 ...

随机推荐

  1. C#基础-----面向对象

    C#基础-----面向对象(一) 分类: C#基础2015-06-08 14:10 2人阅读 评论(0) 收藏 举报 1,面向对象 什么是面向对象?一个分析问题的方式(增强了程序的可扩展性) 几个名词 ...

  2. How Do Annotations Work in Java?--转

    原文地址:https://dzone.com/articles/how-annotations-work-java Annotations have been a very important par ...

  3. 帮助你实现漂亮界面的14套免费的 HTML/CSS 源码

    在网络上能找很多免费的 PSD 格式素材,但是很少有 HTML/CSS 界面组件下载.在这篇文章中,收集了14套免费的 HTML/CSS 界面源码分享给前端设计师和开发者们.这些组件包括按钮.滑块.表 ...

  4. android中出现Error retrieving parent for item: No resource found that matches the Theme.AppCompat.Light

    styles.xml中<style name="AppBaseTheme" parent="Theme.AppCompat.Light">提示如下错 ...

  5. 记一个同时支持模糊匹配和静态推导的Atom语法补全插件的开发过程: 序

    简介 过去的一周,都睡的很晚,终于做出了Atom上的APICloud语法提示与补全插件:apicloud_autocomplete.个中滋味,感觉还是有必要记录下来的.代码基于 GPL-3.0 开源, ...

  6. Wamp 简单使用方法

    1.在wamp的安装目录 \bin\apache\Apache2.4.4\conf 中找到  httpd.conf文件删除 Include conf/extra/httpd-vhosts.conf 这 ...

  7. IOS 字典快速转换为Model 模型

    一般情况下IOS得局部页面加载的过程是,创建一个Model然后,将Nib文件与Model进行关联,然后能够快速的获取到Nib文件上的控件实例.操作生成页面. 但是原生的内容是没有直接通过Json获取M ...

  8. html中charset和content-language的区别

    假设下面的这一段html中meta的两行配置. <html> <head> <meta http-equiv="Content-Type" conte ...

  9. 为什么要用 Bootstrap

    [Bootstrap](http://hovertree.com/menu/bootstrap/) 是由两个 twitter 员工开发并开源的前端框架,非常火爆,而如此火爆自然有它的道理,在我们团队的 ...

  10. C# ~ 数据库连接

    C#连接数据库(SQL Server)进行数据的读取和写入,学习之. 1. 数据库连接 服务器:“Data Source=服务器IP; Initial Catalog=数据库; User ID=用户名 ...