/// <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 > 0) { 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 ? 0 : int.Parse(spfile.Item["ImageWidth"].ToString()); //图片高度 doc.Height = spfile.Item["ImageHeight"] == null ? 0 : 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
时间: 2024-11-08 21:37:06