如何对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# 某天,我想检查一下电脑硬盘的的使用情况,作为一个命令控,废 ...
随机推荐
- [转载]Office Visio快捷键
“帮助”任务窗格和“帮助”窗口 使用“帮助”任务窗格和“帮助”窗口 通过“帮助”任务窗格,您可以访问“Microsoft Office Visio 帮助”的全部内容,该窗格显示为 Microsoft ...
- javascript学习总结(一):基础知识。
1 数据类型a.数据类型共有7种,字符串(string).数字(number).布尔(boolean).数组(array).对象(object).Null.Undefined. 其中布尔(逻辑)类型只 ...
- 200、301、302、304、404等HTTP状态码
在网站建设的实际应用中,容易出现很多小小的失误,就像mysql当初优化不到位,影响整体网站的浏览效果一样,其实,网站的常规http状态码的表现也是一样,Google无法验证网站几种解决办法,提及到由于 ...
- OGNL和ValueStack
OGNL简介 OGNL的全称是Object Graph Navigation Language,即对象导航图语言.它是一个开源项目,工作在视图层,其通过简单一致的表达式语言来读取合适者Java对象的属 ...
- 页面置换算法 - FIFO、LFU、LRU
缓存算法(页面置换算法)-FIFO. LFU. LRU 在前一篇文章中通过leetcode的一道题目了解了LRU算法的具体设计思路,下面继续来探讨一下另外两种常见的Cache算法:FIFO. LFU ...
- a[href$=".pdf"]解释
看过书上的解释,其中$的意思其实是ends with的意思,解释起来就是说选择所有链接指向PDF文件的链接标签,当然还可以是其他类型的文件(.mp4,.doc,.mp4): 当然,这个需要你的浏览器支 ...
- C#去掉HTML标记
该方法亲测可行,下面直接粘贴代码. public string RemoveHTMLTags(string htmlStream) { if (htmlStream == null) { throw ...
- Android网页浏览器的开发
Android网页浏览器的核心Widget是包含了WebKit的WebView. 首先,布局文件activity_main.xml: <LinearLayout xmlns:android=&q ...
- 获取Android版本信息和电话信息
Android的版本信息可以通过android.os.Build获得,电话信息可以通过TelephonyManager获得,代码如下: private void get_infor(){ sd ...
- Scalaz(39)- Free :a real monadic program
一直感觉FP比较虚,可能太多学术性的东西,不知道如何把这些由数学理论在背后支持的一套全新数据类型和数据结构在现实开发中加以使用.直到Free Monad,才真正感觉能用FP方式进行编程了.在前面我们已 ...