使用“管理个人视图”以编程方式创建个人列表视图仅权限

发布于 2024-10-13 08:17:13 字数 886 浏览 3 评论 0原文

在我目前正在进行的项目中,我必须为给定列表创建个人列表视图(SharePoint 2007)。这是我的代码(currListSPList):

System.Collections.Specialized.StringCollection viewFields = currList.Views[BaseViewID].ViewFields.ToStringCollection();
SPView searchView = currList.Views.Add(SearchViewName, viewFields, query, 100, true, false, Microsoft.SharePoint.SPViewCollection.SPViewType.Html, true);

当用户有权将元素添加到列表时,一切工作正常。为用户创建视图,该用户对列表具有除添加项目之外的所有权限,会出现“访问被拒绝”错误。从 SharePoint 本身添加视图是可行的。

我在这里发现了同样的问题: http://us. Generation -nt.com/security-issue-while-creating-personal-view-programmatically-help-86373652.html 所以这个问题并不新鲜。

//编辑: 如果我创建个人视图(将项目添加到列表并管理个人视图权限),我稍后可以仅使用管理个人视图权限修改此视图(从中删除视图字段等)。 有趣的是,如果我之前创建了这个个人视图,我可以修改这个视图

In project, I'm currently working on, I have to create personal list view for given list (SharePoint 2007). Here is my code (currList is SPList):

System.Collections.Specialized.StringCollection viewFields = currList.Views[BaseViewID].ViewFields.ToStringCollection();
SPView searchView = currList.Views.Add(SearchViewName, viewFields, query, 100, true, false, Microsoft.SharePoint.SPViewCollection.SPViewType.Html, true);

Everything's working fine when the user has permission to ADD elements to the list. Creating view for user, which has ALL permissions to the list except adding items gives "Access is denied" error. Adding view from SharePoint itself works.

I've found the same problem here:
http://us.generation-nt.com/security-issue-while-creating-personal-view-programmatically-help-86373652.html
so the problem isn't new.

//EDIT:
If I create personal view (having add items to list and manage personal views permissions) I can later modify this view (remove view fields from it, etc.) with manage personal views permnission only.
What's interesting is thatif I've created this personal vier earlier I can modify this view

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

向日葵 2024-10-20 08:17:13

如果您知道从 UI 添加视图是有效的,您可以尝试复制那里发生的情况。

使用firebug,你可以看到发生了什么,基本上ViewNew页面提交到这个url

http://server.local/_vti_bin/owssvr.dll?CS=65001&BaseViewID=1
    &Cmd=NewView&ContentTypeId=0x&IsThereAQuery=FALSE
    &List=%7BE30D413B-B7E9-47EB-9D69-BC1D3A76A3FD%7D&NewViewName=YourNewView
    &Personal=TRUE

但是有更多的参数。

如果你确实需要这个功能,可以尝试一下。

If you know that adding views from the UI works, you can try replicating what is happening there.

Using firebug, you can see what is going on, basically the ViewNew page submits to this url

http://server.local/_vti_bin/owssvr.dll?CS=65001&BaseViewID=1
    &Cmd=NewView&ContentTypeId=0x&IsThereAQuery=FALSE
    &List=%7BE30D413B-B7E9-47EB-9D69-BC1D3A76A3FD%7D&NewViewName=YourNewView
    &Personal=TRUE

But with a many more parameters.

If you really need this feature, you could try that.

帥小哥 2024-10-20 08:17:13

SharePoint 2010 中仍然存在问题。无法从代码中使用“管理个人视图”添加视图,但可以从 UI 中添加视图。作为新项目中的解决方法,我创建了 JS 脚本,该脚本:

  1. 创建视图页面加载到不可见框架
  2. 填充视图名称字段
  3. 选择“创建个人视图”复选框
  4. 单击 >OK 按钮
  5. 删除框架

我正在使用 jQuery 来执行此操作。单击按钮会导致回发,因此必须对其进行处理:

createPersonalView = function (callback) {
    var url = siteCollectionUrl + '_layouts/ViewNew.aspx?List={' + listId + '}'
        + '&Source=' + window.location.href;

    $someDiv.append('<iframe class="view-creator" style="display:none;"></iframe>');

    $someDiv.find('iframe.view-creator').attr('src', url);
    $someDiv.find('iframe.view-creator').load(function () {
        var $iframe = $(this);
        $iframe.contents().find('#ViewName').attr('value', "My personal view");
        $iframe.contents().find('input#PersonalView0').attr('CHECKED', 'true');

        $iframe.unbind('load');
        $iframe.load(function () {
            $iframe.remove();
            callback(); //it's done! :D
        });

        $iframe.contents().find('#onetidSaveItemtop').click();
    });
};

执行一次就足够了。当您拥有视图后,可以使用管理个人视图权限进行更新。

Problem still exists in SharePoint 2010. Adding views with Manage personal views is not possible from code, but it's possible from UI. As a workaround in new project I've created JS script which:

  1. loads Create View page to invisible frame
  2. fills View Name field
  3. selects "Create a Personal View" checkbox
  4. clicks OK button
  5. removes frame

I'm using jQuery to do this. Clicking button causes postback, so it must be handled:

createPersonalView = function (callback) {
    var url = siteCollectionUrl + '_layouts/ViewNew.aspx?List={' + listId + '}'
        + '&Source=' + window.location.href;

    $someDiv.append('<iframe class="view-creator" style="display:none;"></iframe>');

    $someDiv.find('iframe.view-creator').attr('src', url);
    $someDiv.find('iframe.view-creator').load(function () {
        var $iframe = $(this);
        $iframe.contents().find('#ViewName').attr('value', "My personal view");
        $iframe.contents().find('input#PersonalView0').attr('CHECKED', 'true');

        $iframe.unbind('load');
        $iframe.load(function () {
            $iframe.remove();
            callback(); //it's done! :D
        });

        $iframe.contents().find('#onetidSaveItemtop').click();
    });
};

It's enough to do this once. When you have view then it can be updated with Manage personal views permission.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文