在SharePoint中创建自定义文档库

在SharePoint中创建自定义文档库

本文介绍了在SharePoint中创建自定义文档库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SharePoint页面中有一个文档库,其中有10个文档.

I have a document library in my SharePoint page and there are 10 documents in it.

如果用户A已登录,我希望他仅在该文档库中查看其中的5个文档.

If User A is logged in I want him to only see 5 of those documents in that document library.

如何创建一些自定义文档库以使其正常工作?

How can I create some custom document library for this to work?

我已经安装了MOSS.

I have MOSS installed.

提前谢谢!

推荐答案

编写一个ItemEventReceiver,它会根据库中的字段(即具有不同角色的列)来破坏权限.

Write an ItemEventReceiver that breaks the permissions based on a field in the library, i.e. a column that holds the different roles .

为此,我们创建了一个列表,该列表包含与共享点组关联的所有角色.

We have done this by creating a list that holds all roles coupled to sharepoint groups.

管理员->网站所有者(SPGroup),公司管理员(SPGroup)

经理->经理(SPGroup)

然后在我们的内容类型中,此列表中有一个查找列.

then in our content type we have a lookup column to this list.

这是ItemEventReceiver的代码:

Here's the code for the ItemEventReceiver:

public override void ItemUpdated(SPItemEventProperties properties)
{
lock (_lock)
{
try
{
    using (SPSite site = new SPSite(properties.SiteId,
            properties.ListItem.ParentList.ParentWeb.Site.SystemAccount.UserToken))
    using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
    {
        web.AllowUnsafeUpdates = true;
        var item = web.Lists[properties.ListId].GetItemById(properties.ListItemId);

        var roles = item["Roles"] as SPFieldLookupValueCollection;
        var rolesList = web.Site.RootWeb.Lists["Company Roles"];
        var groupsToAdd = new List<SPFieldUserValue>();

        if (item.HasUniqueRoleAssignments)
        {
            item.ResetRoleInheritance();
            item = item.ParentList.GetItemById(item.ID);
        }

        if (roles != null && roles.Count > 0)
        {
            // Iterate over the roles and see if there is a group associated
            foreach (var role in roles)
            {
                var roleItem = rolesList.GetItemById(rol.LookupId);
                if (roleItem != null)
                {
                    // This is the SPgroup field in the rolesList
                    var groups = roleItem["Groups"] as SPFieldUserValueCollection;
                    if (groups != null)
                    {
                        groupsToAdd.AddRange(from g in groups
                                             where g.User == null
                                             select g);
                    }
                }
            }
            if (groupsToAdd.Count > 0)
            {
                item.BreakRoleInheritance(false);
                foreach (var value in groupsToAdd)
                {
                    var group = web.Groups[value.LookupValue];
                    var assignment = web.RoleAssignments.GetAssignmentByPrincipal(group);
                    item.RoleAssignments.Add(assignment);
                }
            }
        }

        DisableEventFiring();
        item.SystemUpdate(false);
        EnableEventFiring();
    }
}
catch (Exception ex)
{
    //LOG ERROR
}
}
}

这篇关于在SharePoint中创建自定义文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:08