Sharepoint-捕获NewForm.aspx/Edit.aspx的保存事件

Sharepoint-捕获NewForm.aspx/Edit.aspx的保存事件,sharepoint,Sharepoint,我喜欢在创建或编辑项目后自定义编辑用户权限 客户端不接受为此使用工作流,因为有时工作流启动较晚。 我发现了一种Javascript方法: 函数预存储项{…} 但由于安全原因,这不是我想要的,我仍然不认为你们可以在javascript中更改用户的权限,我希望不会。 我只想编辑NewForm.aspx并添加C代码,这些代码将在添加/编辑项之前或之后立即执行 谢谢为什么不创建一个SPItemEventReceiver并将其绑定到列表/内容类型 您必须等待项目创建完成,然后在其上断开RoleInheri

我喜欢在创建或编辑项目后自定义编辑用户权限

客户端不接受为此使用工作流,因为有时工作流启动较晚。 我发现了一种Javascript方法: 函数预存储项{…} 但由于安全原因,这不是我想要的,我仍然不认为你们可以在javascript中更改用户的权限,我希望不会。 我只想编辑NewForm.aspx并添加C代码,这些代码将在添加/编辑项之前或之后立即执行


谢谢

为什么不创建一个SPItemEventReceiver并将其绑定到列表/内容类型

您必须等待项目创建完成,然后在其上断开RoleInheritance

但是,请注意,如果用户添加该项,然后立即尝试打开DispForm.aspx,则会出现一些问题。这是因为事件接收器在并行线程上工作,如果此时执行BreakRoleInheritance,则用户可能没有对项目的读取权限。因此,可能会出现拒绝访问错误

编辑:当您想要部署事件处理程序时,通常会创建一个可以在web范围内激活/停用的功能。然后捕捉激活的功能并调用如下函数:

Public Sub AddEventHandlerToList( _
          ByVal opList As SPList, _
          ByVal spAssemblyName As String, _
          ByVal spClassName As String, _
          ByVal ipType As SPEventReceiverType)
    opList.EventReceivers.Add(ipType, spAssemblyName, spClassName)
    opList.Update()
End Sub
该特征可定义为:

<?xml version="1.0" encoding="utf-8"?>
 <Feature  Id="{ABABABE1-1234-5678-9012-345678912345}"
      Title="MySuperFeature
      Description="Something more descriptive here"
      Scope="Web"
      DefaultResourceFile="core"
      ReceiverAssembly="your.assembly.name, Version=1.0.0.0, Culture=neutral, PublicKeyToken=546479a7bab11231"
      ReceiverClass="your.namespace.MyListHandler"   
      xmlns="http://schemas.microsoft.com/sharepoint/">       
</Feature>
然后,实现您自己的保存功能:

Public Sub onSave(ByVal sender As Object, ByVal e As EventArgs)
    Dim sRedirectUrl As String
    Dim operation As SPLongOperation = Nothing
        operation = New SPLongOperation(Me.Page)
        operation.Begin()

        If SaveButton.SaveItem(SPContext.Current, False, "") Then
            sRedirectUrl = SPUrlUtility.CombineUrl(SPContext.Current.Site.Url, SPContext.Current.List.Forms.Item(PAGETYPE.PAGE_DISPLAYFORM).Url)
            sRedirectUrl &= "?ID=" & SPContext.Current.Item.ID
        End If

        SPContext.Current.Item.BreakRoleInheritance(false);

        operation.End(sRedirectUrl)
End Sub

谢谢,我不知道。我将在NewForm.aspx中搜索如何使用SPItemEventReceiver。非常感谢。但如何将列表与此事件绑定?SPWeb web=SPContext.Current.web;SPContentType ct=web.ContentTypes[MyList];SPEventReceiverDefinition eventReceiver=ct.EventReceivers.Add;这里,ct为空,Mylist为costum列表,web.ContentTypes的集合中没有我的列表。谢谢。如果我能用我的NewForm.aspx做任何事情会更好。无论如何,我会创建一个功能。我希望创建一个功能很容易:谢谢,我转到这个文件夹添加xml。C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES。但是,关于装配,我似乎必须开发一个装配并将其安装在gac中,这是一个大问题,因为它会给维护带来问题。是否仍需要知道不创建自己的程序集?SPContext.Current.FormContext.OnSaveHandler=OnSave;这就是我一直在寻找的。非常感谢。
 SPContext.Current.FormContext.OnSaveHandler = AddressOf onSave
Public Sub onSave(ByVal sender As Object, ByVal e As EventArgs)
    Dim sRedirectUrl As String
    Dim operation As SPLongOperation = Nothing
        operation = New SPLongOperation(Me.Page)
        operation.Begin()

        If SaveButton.SaveItem(SPContext.Current, False, "") Then
            sRedirectUrl = SPUrlUtility.CombineUrl(SPContext.Current.Site.Url, SPContext.Current.List.Forms.Item(PAGETYPE.PAGE_DISPLAYFORM).Url)
            sRedirectUrl &= "?ID=" & SPContext.Current.Item.ID
        End If

        SPContext.Current.Item.BreakRoleInheritance(false);

        operation.End(sRedirectUrl)
End Sub