开发者

Creating personal list view programmatically with "Manage personal views" permissions only

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 SPLis开发者_JAVA百科t):

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜