MOSS 2007 - Changing ListItem permissions in EventReciever
- From: "ripos" <Timofey.Basanov@xxxxxxxxx>
- Date: 16 Oct 2006 04:16:50 -0700
I'm using MOSS 2007 B2TR.
I need the next functionality: when user adds new element to forms
library he and only he can view it later.
I create this next way:
1) Feature registrates FeatureEventReciever
2) FeatureEventReciever registrates ListItemEventReciever
3) ItemAdded event changes access rights of item that was created to
'currentuser->view, admin->full'.
I'm not sure, that this is the perfect way. Is there are others?
But I encounter the problem:
This code is runned in the context of user, that added an item. So
rightless users can not change permissions, because they do not have
appropriate permissions.
I can not give them the rights to change the rights, cause then they
can do bad stuff...
So I need to impersonate programmatically Admin user.
But it did not work. =(
I tried "advapi32.dll"/LogonUser(...)+DuplicateToken(...) function. It
did work.
But every call to SP libs inside the impersonated context lead to:
InnerException {"Cannot complete this action.\n\nPlease try again."}
System.Exception {System.Runtime.InteropServices.COMException}
Source: Microsoft.SharePoint
StackTrace:
at
Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback(String
bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml,
SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback,
ISPDataCallback pPagingCallback, ISPDataCallback pSchemaCallback)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()
at Microsoft.SharePoint.SPListItemCollection.get_Item(Int32 iIndex)
at Microsoft.SharePoint.SPListItem.EnsureItemIsValid()
at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32
columnNumber, Boolean bRaw)
at Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean
bThrowException)
at Microsoft.SharePoint.SPListItem.GetValue(String strName)
at Microsoft.SharePoint.SPListItem.get_Url()
at Microsoft.SharePoint.SPListItem.InitSecurity()
at Microsoft.SharePoint.SPListItem.get_SecurableObjectImpl()
at Microsoft.SharePoint.SPListItem.get_AllRolesForCurrentUser()
And all the fields of addedItem show the same error in debugger.
What I'm doing wrong?..
Is there any other way of impersonating?.. should I try to use COM+ or
WebServices?..
.
- Prev by Date: Re: Licensing.
- Next by Date: Import Business Data List into regular List
- Previous by thread: Re: Licensing.
- Next by thread: Import Business Data List into regular List
- Index(es):
Relevant Pages
|
|