我应该创建自己的对象模型来处理复杂的 Sharepoint 对象吗? [英] Should I create my own Object Model to handle the complex the Sharepoint objects?

查看:50
本文介绍了我应该创建自己的对象模型来处理复杂的 Sharepoint 对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 SharePoint API 做一些相当简单但似乎几乎不可能完成的任务.

I am trying to do something fairly simple but seems like a near impossible task with the SharePoint API.

我的 SharePoint 数据结构如下:

My SharePoint Data Structure is like:

-文件夹
--- 子文件夹
--------项目 A
--------项目 B
--------项目 C
--------项目 D

-Folder
--- Sub Folder
--------Item A
--------Item B
--------Item C
--------Item D

由于某些奇怪的原因,您无法以您期望的分层方式访问文件夹和子文件夹!当我遍历 List 时,它将返回所有忽略层次结构的项目(即它将返回列表中的所有内容).更糟糕的是,您不知道该项目是否为文件夹,以便在代码中管理结构.

For some strange reason you cannot access the Folder and subfolders in the hierarchical manner that you would expect! When I iterate over the List it will return all the items ignoring the hierarchical structure (i.e. it will return everything in the list). Worse, you don’t event know if the item is a Folder or not in order to manage the structure in code.

现在我正在编写自定义对象,以使 SharePoint 对象模型更有意义,并按我期望的层次结构对数据进行分组.我计划按如下方式映射我的 SharePoint 项目:

Now I am writing Custom Objects to make the SharePoint object model a bit more meaningful and group data in the hierarchical that I expect. I'm planning for my SharePoint items to be mapped as follows:

public class Folder
{
    public Folder Parent {get; set;}
    public Folder Root {get; set;}
    public IList<Item> Items {get; set;}
}

有没有人做过类似的事情,或者你是如何在 SharePoint 中管理这个限制的?

Has anyone done something similar or how did you manage this limitation in SharePoint?

如果我开始映射到我的自定义对象模型,是否有任何经验教训和需要注意的事项?

Is there any lessons learned and things to watch out for if I start mapping to my custom object model?

我的最终解决方案是遍历从 list.RootFolder.SubFolders 开始的文件夹.

My final solution was too loop through the folder starting from list.RootFolder.SubFolders.

    var query = from SPList list in Utils.GetList(webRelativeUrl, listName)
                from SPFolder folder in list.RootFolder.SubFolders
                where folder.Name.ToLower() != "forms"
                select new Folder  //Custom Object
                {
                    Name = folder.Name,
                    Children = (from SPFolder subFolder in folder.SubFolders //Further looping of sub folders                                       
                                select new Folder
                                {
                                     Name = subFolder.Name,
                                     Items = (from SPFile file in subFolder.Files
                                              select new Item
                                               {
                                               //Mapping code omitted
                                               }                                             ).ToList()
                                } 
                                        {)
                }

    return query.ToList();

推荐答案

对于您的特定目的,从列表中获取 SPList.RootFolder 并从那里开始工作,递归遍历每个中的子文件夹和项目有什么问题(*)文件夹?

For your specific purpose, what is wrong(*) with getting the SPList.RootFolder from the list and working from there, recursively traversing the subfolders and items in each folder?

(*) 这里忽略性能方面...

(*) Ignoring the performance aspect here...

这篇关于我应该创建自己的对象模型来处理复杂的 Sharepoint 对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆