/// <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. Unity 游戏存档 PlayerPrefs类的用法

    unity3d提供了一个用于本地持久化保存与读取的类--PlayerPrefs.工作原理非常简单,以键值对的形式将数据保存在文件中,然后程序可以根据这个名称取出上次保存的数值.    PlayerPr ...

  2. Android基于mAppWidget实现手绘地图(十五)–如何控制放大缩小

    一般来说,可以使用以下几种方式来控制地图的放大/缩小 : 1. 使用控件底部的缩放按钮 2.双击控件 3.pinch手势 4.物理按键 :I键标识缩小  :O键表示放大.(只有设备具有物理按键才行) ...

  3. 机器学习&数据挖掘笔记_23(PGM练习七:CRF中参数的学习)

    前言: 本次实验主要任务是学习CRF模型的参数,实验例子和PGM练习3中的一样,用CRF模型来预测多张图片所组成的单词,我们知道在graph model的推理中,使用较多的是factor,而在grap ...

  4. BonBon - 使用 CSS3 制作甜美的糖果按钮

    BonBon 是一组使用 CSS3 制作的甜美的糖果按钮样式.在过去,我们都是使用图片或者 JavaScript 来实现漂亮的按钮效果,随着越来越多的浏览器对 CSS3 的支持和完善,使用 CSS3 ...

  5. [emacs] Drawing uml under emacs org-mode using plantUML - 类图

    [emacs] Drawing uml under emacs org-mode using plantUML - 类图 // */ // ]]>   [emacs] Drawing uml u ...

  6. 移植SlidingMenu Android library,和安装example出现的问题解决

    很多项目都用到类似左侧滑动菜单的效果,比如facebook,evernote,VLC for android等等,这很酷 源代码可以从GitHub的https://github.com/jfeinst ...

  7. Elasticsearch聚合 之 Date Histogram聚合

    Elasticsearch的聚合主要分成两大类:metric和bucket,2.0中新增了pipeline还没有研究.本篇还是来介绍Bucket聚合中的常用聚合--date histogram.参考: ...

  8. CSS3魔法堂:认识@font-face和Font Icon

    一.前言 过去我们总通过图片来美化站点的LOGO.标题.图标等,而现在我们可以通过@font-face获取另一种更灵活的美化方式. 二.看看例子 /* 定义 */ @font-face { font- ...

  9. 开源服务专题之------sshd服务安装管理及配置文件理解和安全调优

    本专题我将讨论一下开源服务,随着开源社区的日趋丰富,开源软件.开源服务,已经成为人类的一种公共资源,发展势头可谓一日千里,所以不可不知.SSHD服务,在我们的linux服务器上经常用到,很重要,涉及到 ...

  10. SQL Server获取下一个编码字符串的实现方案分割和进位

        我在前一种解决方案SQL Server获取下一个编码字符实现和后一种解决方案SQL Server获取下一个编码字符实现继续重构与增强两篇博文中均提供了一种解决编码的方案,考虑良久对比以上两种方 ...