本文整理汇总了C#中SPListItem.DoesUserHavePermissions方法的典型用法代码示例。如果您正苦于以下问题:C# SPListItem.DoesUserHavePermissions方法的具体用法?C# SPListItem.DoesUserHavePermissions怎么用?C# SPListItem.DoesUserHavePermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPListItem
的用法示例。
在下文中一共展示了SPListItem.DoesUserHavePermissions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentUserPermissionsOnItem
private string[] GetCurrentUserPermissionsOnItem(SPWeb web, SPListItem item)
{
var permissions = new List<string>();
if (item.DoesUserHavePermissions(SPBasePermissions.EditListItems))
{
permissions.Add("Edit");
// If users have permissions to edit all items or
// if user should only have edit permissions on their own items
var list = this.listLocator.GetByUrl(web, this.config.DiscussionListInfo.WebRelativeUrl);
if ((list.WriteSecurity == 1) || (list.WriteSecurity == 2))
{
var currentUserLogin = SPContext.Current.Web.CurrentUser.LoginName;
var authorUserLogin = new SPFieldUserValue(list.ParentWeb, item[SPBuiltInFieldId.Author].ToString()).User.LoginName;
if (authorUserLogin.Equals(currentUserLogin, StringComparison.OrdinalIgnoreCase))
{
permissions.Add("EditAuthor");
}
}
}
if (item.DoesUserHavePermissions(SPBasePermissions.ManageWeb))
{
permissions.Add("ManageWeb");
}
if (item.DoesUserHavePermissions(SPBasePermissions.ManageLists))
{
permissions.Add("ManageLists");
}
return permissions.ToArray();
}
示例2: CancelWorkflows
/// <summary>
/// Cancels the workflows. This code is a re-engineering of the code that Microsoft uses
/// when approving an item via the browser. That code is in Microsoft.SharePoint.ApplicationPages.ApprovePage.
/// </summary>
/// <param name="test">If true test the change only (don't make any changes).</param>
/// <param name="list">The list.</param>
/// <param name="item">The item.</param>
private void CancelWorkflows(bool test, SPList list, SPListItem item)
{
if (list.DefaultContentApprovalWorkflowId != Guid.Empty &&
item.DoesUserHavePermissions((SPBasePermissions.ApproveItems |
SPBasePermissions.EditListItems)))
{
// If the user has rights to do so then we need to cancel any workflows that
// are associated with the item.
SPSecurity.RunWithElevatedPrivileges(
delegate
{
foreach (SPWorkflow workflow in item.Workflows)
{
if (workflow.ParentAssociation.Id !=
list.DefaultContentApprovalWorkflowId)
{
continue;
}
SPWorkflowManager.CancelWorkflow(workflow);
Logger.Write("Cancelling workflow {0} for item: {1} ({2})", workflow.WebId.ToString(), item.ID.ToString(), item.Url);
}
});
}
}